Skip to content

Commit 88c29d1

Browse files
committed
add test for a large plan
1 parent 7002c87 commit 88c29d1

File tree

1 file changed

+386
-0
lines changed

1 file changed

+386
-0
lines changed

test/plan/test_plan_large.js

+386
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,386 @@
1+
import test from 'tape'
2+
import { pause } from '@holochain/tryorama'
3+
import {
4+
buildPlayer,
5+
mockIdentifier,
6+
mockAddress,
7+
} from '../init.js'
8+
9+
const testCommitmentProps = {
10+
action: 'raise',
11+
resourceClassifiedAs: ['some-resource-type'],
12+
resourceQuantity: { hasNumericalValue: 1, hasUnit: mockIdentifier() },
13+
provider: mockAddress(),
14+
receiver: mockAddress(),
15+
}
16+
17+
test('Plan links & queries', async (t) => {
18+
// display the filename for context in the terminal and use .warn
19+
// to override the tap testing log filters
20+
console.warn(`\n\n${import.meta.url}`)
21+
const alice = await buildPlayer(['combined'])
22+
23+
// ===CREATE PLAN===
24+
let start = new Date()
25+
try {
26+
let resp = await alice.graphQL(`
27+
mutation($rs: PlanCreateParams!) {
28+
res: createPlan(plan: $rs) {
29+
plan {
30+
id
31+
}
32+
}
33+
}
34+
`, {
35+
rs: {
36+
name: 'test plan',
37+
created: new Date(),
38+
due: new Date(),
39+
note: 'just testing, nothing was rly planned',
40+
},
41+
})
42+
let end = new Date()
43+
console.log('⏱︎ time to create plan:', (end - start) * 0.001, 'seconds ⏱︎')
44+
t.ok(resp.data.res.plan.id, 'plan created')
45+
const planId = resp.data.res.plan.id
46+
47+
// ===CREATE 4 COMMITMENTS AND 4 PROCESSES===
48+
// define async function to create a process and commitment
49+
const createProcessAndCommitment = async (processName, commitmentNote) => {
50+
const resp = await alice.graphQL(`
51+
mutation($p: ProcessCreateParams!, $c: CommitmentCreateParams!) {
52+
process: createProcess(process: $p) {
53+
process {
54+
id
55+
}
56+
}
57+
commitment: createCommitment(commitment: $c) {
58+
commitment {
59+
id
60+
}
61+
}
62+
}
63+
`, {
64+
p: {
65+
plannedWithin: planId,
66+
name: processName,
67+
note: 'linked process note 1',
68+
},
69+
c: {
70+
independentDemandOf: planId,
71+
plannedWithin: planId,
72+
note: commitmentNote,
73+
due: new Date(Date.now() + 86400000),
74+
...testCommitmentProps,
75+
},
76+
})
77+
return resp.data.process.process.id
78+
}
79+
80+
start = new Date()
81+
let processId1 = await createProcessAndCommitment('linked process name 1', 'linked commitment 1')
82+
t.ok(processId1, 'process 1 created')
83+
let processId2 = await createProcessAndCommitment('linked process name 2', 'linked commitment 2')
84+
t.ok(processId2, 'process 2 created')
85+
let processId3 = await createProcessAndCommitment('linked process name 3', 'linked commitment 3')
86+
t.ok(processId3, 'process 3 created')
87+
let processId4 = await createProcessAndCommitment('linked process name 4', 'linked commitment 4')
88+
t.ok(processId4, 'process 4 created')
89+
end = new Date()
90+
91+
console.log('⏱︎ time to create 4 commitments and 4 processes:', (end - start) * 0.001 , 'seconds ⏱︎')
92+
93+
// ===ADD ORGANIZATION===
94+
const exampleOrganization = {
95+
name: 'test organization',
96+
image: 'https://org.png',
97+
classifiedAs: ['org'],
98+
note: 'test organization note',
99+
}
100+
start = new Date()
101+
let createOrgResp = await alice.graphQL(
102+
`
103+
mutation($rs: OrganizationCreateParams!) {
104+
res: createOrganization(organization: $rs) {
105+
agent {
106+
id
107+
revisionId
108+
}
109+
}
110+
}
111+
`,
112+
{
113+
rs: exampleOrganization,
114+
},
115+
)
116+
end = new Date()
117+
console.log('⏱︎ time to create organization:', (end - start) * 0.001, 'seconds ⏱︎')
118+
let organizationId = createOrgResp.data.res.agent.id
119+
120+
// ===ADD UNIT DOLLAR===
121+
start = new Date()
122+
resp = await alice.graphQL(`
123+
mutation($u: UnitCreateParams!) {
124+
res: createUnit(unit: $u) {
125+
unit {
126+
id
127+
}
128+
}
129+
}
130+
`, {
131+
u: {
132+
label: 'US Dollar',
133+
symbol: 'USD',
134+
},
135+
})
136+
end = new Date()
137+
console.log('⏱︎ time to create unit:', (end - start) * 0.001, 'seconds ⏱︎')
138+
t.ok(resp.data.res.unit.id, 'unit created')
139+
const unitId = resp.data.res.unit.id
140+
141+
// ===ADD RESOURCE SPECIFICATION===
142+
start = new Date()
143+
resp = await alice.graphQL(`
144+
mutation($rs: ResourceSpecificationCreateParams!) {
145+
res: createResourceSpecification(resourceSpecification: $rs) {
146+
resourceSpecification {
147+
id
148+
}
149+
}
150+
}
151+
`, {
152+
rs: {
153+
name: 'test resource specification',
154+
defaultUnitOfResource: unitId,
155+
note: 'test resource specification note',
156+
},
157+
})
158+
end = new Date()
159+
console.log("RS ID", resp.data.res.resourceSpecification.id)
160+
console.log('⏱︎ time to create resource specification:', (end - start) * 0.001, 'seconds ⏱︎')
161+
t.ok(resp.data.res.resourceSpecification.id, 'resource specification created')
162+
const resourceSpecificationId = resp.data.res.resourceSpecification.id
163+
164+
// ===ADD INPUT AND OUTPUT COMMITMENTS TO PROCESS===
165+
const addInputAndOutputCommitments = async (processId) => {
166+
let com3 = {
167+
'action': 'pickup',
168+
'inputOf': processId,
169+
'provider': organizationId,
170+
'receiver': organizationId,
171+
'due': '2019-11-19T04:29:55.056Z',
172+
'resourceQuantity': { hasNumericalValue: 1, hasUnit: unitId },
173+
'resourceClassifiedAs': ['some-resource-type'],
174+
'note': 'some input will be provided',
175+
}
176+
177+
let com4 = {
178+
'action': 'dropoff',
179+
'outputOf': processId,
180+
'provider': organizationId,
181+
'receiver': organizationId,
182+
'due': '2019-11-19T04:29:55.056Z',
183+
'resourceQuantity': { hasNumericalValue: 1, hasUnit: unitId },
184+
'resourceClassifiedAs': ['some-resource-type'],
185+
'note': 'some input will be provided',
186+
}
187+
188+
resp = await alice.graphQL(`
189+
mutation($c1: CommitmentCreateParams!, $c2: CommitmentCreateParams!) {
190+
commitment1: createCommitment(commitment: $c1) {
191+
commitment {
192+
id
193+
}
194+
}
195+
commitment2: createCommitment(commitment: $c1) {
196+
commitment {
197+
id
198+
}
199+
}
200+
commitment3: createCommitment(commitment: $c1) {
201+
commitment {
202+
id
203+
}
204+
}
205+
commitment4: createCommitment(commitment: $c1) {
206+
commitment {
207+
id
208+
}
209+
}
210+
commitment5: createCommitment(commitment: $c2) {
211+
commitment {
212+
id
213+
}
214+
}
215+
commitment6: createCommitment(commitment: $c2) {
216+
commitment {
217+
id
218+
}
219+
}
220+
commitment7: createCommitment(commitment: $c2) {
221+
commitment {
222+
id
223+
}
224+
}
225+
commitment8: createCommitment(commitment: $c2) {
226+
commitment {
227+
id
228+
}
229+
}
230+
}
231+
`, {
232+
c1: com3,
233+
c2: com4,
234+
})
235+
}
236+
237+
238+
start = new Date()
239+
console.log("creating commitments", start)
240+
await addInputAndOutputCommitments(processId1)
241+
await addInputAndOutputCommitments(processId2)
242+
await addInputAndOutputCommitments(processId3)
243+
await addInputAndOutputCommitments(processId4)
244+
end = new Date()
245+
console.log("commitments created", end)
246+
console.log('⏱︎ time to add 4 input and 4 output commitments to 4 process:', (end - start) * 0.001, 'seconds ⏱︎')
247+
248+
// ===RETRIEVE FULL PLAN===
249+
start = new Date()
250+
resp = await alice.graphQL(`
251+
query {
252+
plan(id: "${planId}") {
253+
independentDemands {
254+
id
255+
}
256+
processes {
257+
id
258+
revisionId
259+
name
260+
meta {
261+
retrievedRevision {
262+
id
263+
time
264+
}
265+
}
266+
committedInputs {
267+
id
268+
revisionId
269+
hasBeginning
270+
action {
271+
id
272+
label
273+
}
274+
meta {
275+
retrievedRevision {
276+
id
277+
time
278+
}
279+
}
280+
providerId
281+
provider {
282+
id
283+
name
284+
}
285+
}
286+
committedOutputs {
287+
id
288+
revisionId
289+
hasBeginning
290+
action {
291+
id
292+
label
293+
}
294+
meta {
295+
retrievedRevision {
296+
id
297+
time
298+
}
299+
}
300+
providerId
301+
provider {
302+
id
303+
name
304+
}
305+
receiverId
306+
resourceQuantity {
307+
hasNumericalValue
308+
hasUnitId
309+
}
310+
}
311+
}
312+
}
313+
}
314+
`,
315+
)
316+
end = new Date()
317+
console.log('⏱︎ time to query full plan:', (end - start) * 0.001, 'seconds ⏱︎')
318+
// t.equal(resp.data.process.plannedWithin.id, planId, 'process -> plan ref OK')
319+
// t.equal(resp.data.commitment.independentDemandOf.id, planId, 'commitment -> plan ref OK')
320+
// t.equal(resp.data.commitment.plannedWithin.id, planId, 'commitment -> plan ref OK')
321+
// t.equal(resp.data.plan.independentDemands.length, 1, 'commitment ref added')
322+
// t.equal(resp.data.plan.independentDemands[0].id, cId, 'commitment ref OK')
323+
// t.equal(resp.data.plan.processes.length, 1, 'process ref added')
324+
// t.equal(resp.data.plan.processes[0].id, pId, 'process ref OK')
325+
326+
// resp = await alice.graphQL(`
327+
// mutation($p: ProcessCreateParams!, $c: CommitmentCreateParams!) {
328+
// process: createProcess(process: $p) {
329+
// process {
330+
// id
331+
// }
332+
// }
333+
// commitment: createCommitment(commitment: $c) {
334+
// commitment {
335+
// id
336+
// }
337+
// }
338+
// }
339+
// `, {
340+
// p: {
341+
// plannedWithin: planId,
342+
// name: 'linked process name 2',
343+
// note: 'linked process note 2',
344+
// },
345+
// c: {
346+
// independentDemandOf: planId,
347+
// // plannedWithin: planId, // not able to add this yet as this field is not currently defined in the CreateCommitmentParams object
348+
// note: 'linked commitment 2',
349+
// due: new Date(Date.now() + 86400000),
350+
// ...testCommitmentProps,
351+
// },
352+
// })
353+
// await pause(100)
354+
// t.ok(resp.data.process.process.id, 'event 2 created')
355+
// t.ok(resp.data.commitment.commitment.id, 'commitment 2 created')
356+
// const p2Id = resp.data.process.process.id
357+
// const c2Id = resp.data.commitment.commitment.id
358+
359+
// resp = await alice.graphQL(`
360+
// query {
361+
// plan(id: "${planId}") {
362+
// independentDemands {
363+
// id
364+
// }
365+
// processes {
366+
// id
367+
// }
368+
// }
369+
// }
370+
// `)
371+
372+
// const sortedCIds = [{ id: c2Id }, { id: cId }]
373+
// const sortedPIds = [{ id: p2Id }, { id: pId }]
374+
375+
// t.equal(resp.data.plan.independentDemands.length, 2, '2nd commitment ref added')
376+
// t.equal(resp.data.plan.independentDemands[0].id, sortedCIds[0].id, 'commitment ref 1 OK')
377+
// t.equal(resp.data.plan.independentDemands[1].id, sortedCIds[1].id, 'commitment ref 2 OK')
378+
// t.equal(resp.data.plan.processes.length, 2, '2nd event ref added')
379+
// t.equal(resp.data.plan.processes[0].id, sortedPIds[0].id, 'process ref 1 OK')
380+
// t.equal(resp.data.plan.processes[1].id, sortedPIds[1].id, 'process ref 2 OK')
381+
} catch (e) {
382+
await alice.scenario.cleanUp()
383+
throw e
384+
}
385+
await alice.scenario.cleanUp()
386+
})

0 commit comments

Comments
 (0)