|
| 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 | + end = new Date() |
| 84 | + |
| 85 | + console.log('⏱︎ time to create 1 commitments and 1 processes:', (end - start) * 0.001 , 'seconds ⏱︎') |
| 86 | + } catch (e) { |
| 87 | + await alice.scenario.cleanUp() |
| 88 | + throw e |
| 89 | + } |
| 90 | + await alice.scenario.cleanUp() |
| 91 | +}) |
0 commit comments