Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit c30c71e

Browse files
committed
Merge remote-tracking branch 'origin/dashboard-view' into damien-review-batch-1
2 parents a621e90 + b9cb983 commit c30c71e

File tree

5 files changed

+392
-44
lines changed

5 files changed

+392
-44
lines changed

src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11

2-
import sensemaker_dimension from './sensemaker_dna/sensemaker/neighbourhood';
2+
import neighbourhood from './sensemaker_dna/sensemaker/neighbourhood';
33
import sensemaker_community_activator from './sensemaker_dna/sensemaker/community_activator';
44
import sensemaker_config from './sensemaker_dna/sensemaker/sm_config';
55
import applet_config from './sensemaker_dna/sensemaker/applet_config';
66
import range from './sensemaker_dna/sensemaker/range';
7+
import dashboard from './sensemaker_dna/sensemaker/dashboard';
78
range();
8-
sensemaker_dimension();
9+
neighbourhood();
910
applet_config();
11+
neighbourhood();
1012
sensemaker_config();
1113
sensemaker_community_activator();
14+
dashboard();
1215

src/sensemaker_dna/sensemaker/applet_config.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export default () =>
223223
"1-scale-total": rangeHash2
224224

225225
},
226+
role_name: "test_provider_dna",
226227
dimensions: {
227228
importance: dimensionHash,
228229
total_importance: objectiveDimensionHash
@@ -235,18 +236,21 @@ export default () =>
235236
// TODO: bring the type back once sensemaker-types are updated
236237
// const appletConfigInput: AppletConfigInput = {
237238
const appletConfigInput: any = {
238-
name: appletConfig.name,
239-
ranges: [integerRange, integerRange2],
240-
dimensions: [configDimension, configObjectiveDimension],
241-
resource_defs: [configResourceDef],
242-
methods: [configMethod],
243-
cultural_contexts: [configCulturalContext],
239+
applet_config_input: {
240+
name: appletConfig.name,
241+
ranges: [integerRange, integerRange2],
242+
dimensions: [configDimension, configObjectiveDimension],
243+
resource_defs: [configResourceDef],
244+
methods: [configMethod],
245+
cultural_contexts: [configCulturalContext],
246+
},
247+
role_name: "test_provider_dna"
244248
}
245249

246250
let maybeAppletConfig: any = await callZomeAlice(
247251
"sensemaker",
248252
"check_if_applet_config_exists",
249-
appletConfigInput.name,
253+
appletConfigInput.applet_config_input.name,
250254
true
251255
);
252256
t.ok(!maybeAppletConfig);
@@ -264,7 +268,7 @@ export default () =>
264268
maybeAppletConfig = await callZomeAlice(
265269
"sensemaker",
266270
"check_if_applet_config_exists",
267-
appletConfigInput.name,
271+
appletConfigInput.applet_config_input.name,
268272
true
269273
);
270274
t.ok(maybeAppletConfig);
Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
1+
import { DnaSource, Record, ActionHash, EntryHash, AppEntryDef, Create } from "@holochain/client";
2+
import {
3+
pause,
4+
runScenario,
5+
Scenario,
6+
createConductor,
7+
addAllAgentsToAllConductors,
8+
cleanAllConductors,
9+
} from "@holochain/tryorama";
10+
import { decode } from "@msgpack/msgpack";
11+
import { AppletConfig, Assessment, AssessmentWithDimensionAndResource, CreateAppletConfigInput, CreateAssessmentInput, Method, RangeValueInteger } from "@neighbourhoods/sensemaker-lite-types";
12+
import { ok } from "assert";
13+
import pkg from "tape-promise/tape";
14+
import { installAgent, sampleAppletConfig } from "../../utils";
15+
const { test } = pkg;
16+
17+
interface TestPost {
18+
title: string;
19+
content: string;
20+
}
21+
22+
export const setUpAliceandBob = async (
23+
with_config: boolean = false,
24+
resource_base_type?: any
25+
) => {
26+
const alice = await createConductor();
27+
const bob = await createConductor();
28+
const {
29+
agentsHapps: alice_happs,
30+
agent_key: alice_agent_key,
31+
ss_cell_id: ss_cell_id_alice,
32+
provider_cell_id: provider_cell_id_alice,
33+
} = await installAgent(
34+
alice,
35+
"alice",
36+
undefined,
37+
with_config,
38+
resource_base_type
39+
);
40+
const {
41+
agentsHapps: bob_happs,
42+
agent_key: bob_agent_key,
43+
ss_cell_id: ss_cell_id_bob,
44+
provider_cell_id: provider_cell_id_bob,
45+
} = await installAgent(
46+
bob,
47+
"bob",
48+
alice_agent_key,
49+
with_config,
50+
resource_base_type
51+
);
52+
await addAllAgentsToAllConductors([alice, bob]);
53+
return {
54+
alice,
55+
bob,
56+
alice_happs,
57+
bob_happs,
58+
alice_agent_key,
59+
bob_agent_key,
60+
ss_cell_id_alice,
61+
ss_cell_id_bob,
62+
provider_cell_id_alice,
63+
provider_cell_id_bob,
64+
};
65+
};
66+
67+
export default () => {
68+
test("test fetching dashboard data", async (t) => {
69+
await runScenario(async (scenario) => {
70+
const {
71+
alice,
72+
bob,
73+
alice_happs,
74+
bob_happs,
75+
alice_agent_key,
76+
bob_agent_key,
77+
ss_cell_id_alice,
78+
ss_cell_id_bob,
79+
provider_cell_id_alice,
80+
provider_cell_id_bob,
81+
} = await setUpAliceandBob();
82+
83+
const callZomeAlice = async (
84+
zome_name,
85+
fn_name,
86+
payload,
87+
is_ss = false
88+
) => {
89+
return await alice.appWs().callZome({
90+
cap_secret: null,
91+
cell_id: is_ss ? ss_cell_id_alice : provider_cell_id_alice,
92+
zome_name,
93+
fn_name,
94+
payload,
95+
provenance: alice_agent_key,
96+
});
97+
};
98+
const callZomeBob = async (
99+
zome_name,
100+
fn_name,
101+
payload,
102+
is_ss = false
103+
) => {
104+
return await bob.appWs().callZome({
105+
cap_secret: null,
106+
cell_id: is_ss ? ss_cell_id_bob : provider_cell_id_bob,
107+
zome_name,
108+
fn_name,
109+
payload,
110+
provenance: bob_agent_key,
111+
});
112+
};
113+
try {
114+
const pauseDuration = 1000
115+
await scenario.shareAllAgents();
116+
await pause(pauseDuration);
117+
118+
// create an entry type in the provider DNA
119+
const createPost: TestPost = {
120+
title: "post 1",
121+
content: "hey!",
122+
};
123+
const createPostEntryHash: EntryHash = await callZomeAlice(
124+
"test_provider",
125+
"create_post",
126+
createPost
127+
);
128+
t.ok(createPostEntryHash);
129+
130+
const createPost2: TestPost = {
131+
title: "post 2",
132+
content: "bye!",
133+
};
134+
const createPostEntryHash2: EntryHash = await callZomeAlice(
135+
"test_provider",
136+
"create_post",
137+
createPost2
138+
);
139+
t.ok(createPostEntryHash2);
140+
141+
const createPost3: TestPost = {
142+
title: "post 3",
143+
content: "I'm back!",
144+
};
145+
const createPostEntryHash3: EntryHash = await callZomeAlice(
146+
"test_provider",
147+
"create_post",
148+
createPost3
149+
);
150+
t.ok(createPostEntryHash3);
151+
await pause(pauseDuration);
152+
153+
// Bob gets the created post
154+
const readPostOutput: Record = await callZomeBob(
155+
"test_provider",
156+
"get_post",
157+
createPostEntryHash
158+
);
159+
t.deepEqual(
160+
createPost,
161+
decode((readPostOutput.entry as any).Present.entry) as any
162+
);
163+
164+
let app_entry_def: AppEntryDef = { entry_index: 0, zome_index: 0, visibility: { Public: null } };
165+
const appletConfigInput = sampleAppletConfig(app_entry_def)
166+
const createAppletConfigInput: CreateAppletConfigInput = {
167+
applet_config_input: appletConfigInput,
168+
role_name: "test_provider_dna",
169+
}
170+
const appletConfig: AppletConfig = await callZomeAlice(
171+
"sensemaker",
172+
"register_applet",
173+
createAppletConfigInput,
174+
true
175+
);
176+
t.ok(appletConfig);
177+
// Wait for the created entry to be propagated to the other node.
178+
await pause(pauseDuration);
179+
180+
// create an assessment on the Post
181+
const createP1Assessment: CreateAssessmentInput = {
182+
value: { Integer: 4 },
183+
dimension_eh: appletConfig.dimensions["likeness"],
184+
resource_eh: createPostEntryHash,
185+
resource_type_eh: appletConfig.resource_types["angryPost"],
186+
maybe_input_dataset: null,
187+
};
188+
189+
const createP1AssessmentEntryHash: EntryHash = await callZomeAlice(
190+
"sensemaker",
191+
"create_assessment",
192+
createP1Assessment,
193+
true
194+
);
195+
t.ok(createP1AssessmentEntryHash);
196+
197+
// Wait for the created entry to be propagated to the other node.
198+
await pause(pauseDuration);
199+
200+
// create a second assessment on the Post
201+
const createP1Assessment2: CreateAssessmentInput = {
202+
value: { Integer: 4 },
203+
dimension_eh: appletConfig.dimensions["likeness"],
204+
resource_eh: createPostEntryHash,
205+
resource_type_eh: appletConfig.resource_types["angryPost"],
206+
maybe_input_dataset: null,
207+
};
208+
209+
const createP1AssessmentEntryHash2: EntryHash = await callZomeAlice(
210+
"sensemaker",
211+
"create_assessment",
212+
createP1Assessment2,
213+
true
214+
);
215+
t.ok(createP1AssessmentEntryHash2);
216+
217+
const createP2Assessment: CreateAssessmentInput = {
218+
value: { Integer: 3 },
219+
dimension_eh: appletConfig.dimensions["likeness"],
220+
resource_eh: createPostEntryHash2,
221+
resource_type_eh: appletConfig.resource_types["angryPost"],
222+
maybe_input_dataset: null,
223+
};
224+
225+
const createP2AssessmentEntryHash: EntryHash = await callZomeAlice(
226+
"sensemaker",
227+
"create_assessment",
228+
createP2Assessment,
229+
true
230+
);
231+
t.ok(createP2AssessmentEntryHash);
232+
233+
// create an assessment on the Post
234+
const createP2Assessment2: CreateAssessmentInput = {
235+
value: { Integer: 3 },
236+
dimension_eh: appletConfig.dimensions["likeness"],
237+
resource_eh: createPostEntryHash2,
238+
resource_type_eh: appletConfig.resource_types["angryPost"],
239+
maybe_input_dataset: null,
240+
};
241+
242+
const createP2AssessmentEntryHash2: EntryHash = await callZomeAlice(
243+
"sensemaker",
244+
"create_assessment",
245+
createP2Assessment2,
246+
true
247+
);
248+
t.ok(createP2AssessmentEntryHash2);
249+
250+
// Wait for the created entry to be propagated to the other node.
251+
await pause(pauseDuration);
252+
253+
// create a second assessment on the Post
254+
const createP3Assessment: CreateAssessmentInput = {
255+
value: { Integer: 2 },
256+
dimension_eh: appletConfig.dimensions["likeness"],
257+
resource_eh: createPostEntryHash3,
258+
resource_type_eh: appletConfig.resource_types["angryPost"],
259+
maybe_input_dataset: null,
260+
};
261+
262+
const createP3AssessmentEntryHash: EntryHash = await callZomeAlice(
263+
"sensemaker",
264+
"create_assessment",
265+
createP3Assessment,
266+
true
267+
);
268+
t.ok(createP3AssessmentEntryHash);
269+
270+
const createP3Assessment2: CreateAssessmentInput = {
271+
value: { Integer: 2 },
272+
dimension_eh: appletConfig.dimensions["likeness"],
273+
resource_eh: createPostEntryHash3,
274+
resource_type_eh: appletConfig.resource_types["angryPost"],
275+
maybe_input_dataset: null,
276+
};
277+
278+
const createP3AssessmentEntryHash2: EntryHash = await callZomeAlice(
279+
"sensemaker",
280+
"create_assessment",
281+
createP3Assessment2,
282+
true
283+
);
284+
t.ok(createP3AssessmentEntryHash2);
285+
286+
// Wait for the created entry to be propagated to the other node.
287+
await pause(pauseDuration);
288+
289+
// define objective dimension
290+
291+
// fetch all assessments
292+
const allAssessments: Array<AssessmentWithDimensionAndResource> = await callZomeAlice(
293+
"sensemaker",
294+
"get_all_assessments",
295+
null,
296+
true
297+
);
298+
console.log('all assessments', allAssessments)
299+
t.deepEqual(allAssessments.length, 6);
300+
const allAssessedPosts = allAssessments.map((a) => decode((a.resource!.entry as any).Present.entry) as TestPost)
301+
t.ok(allAssessedPosts.find((p) => JSON.stringify(p) === JSON.stringify(createPost)))
302+
t.ok(allAssessedPosts.find((p) => JSON.stringify(p) === JSON.stringify(createPost2)))
303+
t.ok(allAssessedPosts.find((p) => JSON.stringify(p) === JSON.stringify(createPost3)))
304+
305+
} catch (e) {
306+
console.log(e);
307+
t.ok(null);
308+
}
309+
310+
await alice.shutDown();
311+
await bob.shutDown();
312+
await cleanAllConductors();
313+
});
314+
});
315+
};
316+

0 commit comments

Comments
 (0)