1 |
|
2 |
|
3 | const tymly = require('./../lib')
|
4 | const path = require('path')
|
5 | const expect = require('chai').expect
|
6 |
|
7 | const UPSERT_STATE_MACHINE = 'tymlyTest_upsert'
|
8 | const WAIT_AND_UPSERT_STATE_MACHINE = 'tymlyTest_waitAndUpsert'
|
9 | const LONG_WAIT_AND_UPSERT_STATE_MACHINE = 'tymlyTest_longWaitAndUpsert'
|
10 |
|
11 | describe('Inject userId through statebox service', function () {
|
12 | this.timeout(process.env.TIMEOUT || 30000)
|
13 | let tymlyService, statebox, storage, userInfo
|
14 |
|
15 | describe('start up', () => {
|
16 | it('boot tymly', done => {
|
17 | tymly.boot(
|
18 | {
|
19 | blueprintPaths: [
|
20 | path.resolve(__dirname, './fixtures/blueprints/wait-and-upsert-blueprint')
|
21 | ],
|
22 | pluginPaths: [
|
23 | path.resolve(__dirname, '../node_modules/@wmfs/tymly-test-helpers/plugins/allow-everything-rbac-plugin'),
|
24 | path.resolve(__dirname, '../node_modules/@wmfs/tymly-test-helpers/plugins/mock-user-info-plugin')
|
25 | ]
|
26 | },
|
27 | (err, tymlyServices) => {
|
28 | expect(err).to.eql(null)
|
29 | tymlyService = tymlyServices.tymly
|
30 | statebox = tymlyServices.statebox
|
31 | storage = tymlyServices.storage
|
32 | userInfo = tymlyServices.userInfo
|
33 | done()
|
34 | }
|
35 | )
|
36 | })
|
37 | })
|
38 |
|
39 | function testBatch (label, tests) {
|
40 | describe(label, () => {
|
41 | describe('fire off state machines', () => {
|
42 | it('set mock userInfo', () => {
|
43 | for (const test of tests) {
|
44 | userInfo.addUser(test.userId, test.userEmail)
|
45 | }
|
46 | })
|
47 |
|
48 | for (const test of tests) {
|
49 | it(test.title, async () => {
|
50 | const execDescription = await statebox.startExecution(
|
51 | {
|
52 | person: test.person
|
53 | },
|
54 | test.stateMachine,
|
55 | {
|
56 | userId: test.userId
|
57 | }
|
58 | )
|
59 |
|
60 | expect(execDescription.status).to.eql('RUNNING')
|
61 |
|
62 | test.execName = execDescription.executionName
|
63 | })
|
64 | }
|
65 | })
|
66 |
|
67 | describe('wait for state machines to finish', () => {
|
68 | tests.reverse()
|
69 | for (const test of tests) {
|
70 | it(test.title, async () => {
|
71 | const executionDescription = await statebox.waitUntilStoppedRunning(test.execName)
|
72 |
|
73 | expect(executionDescription.status).to.eql('SUCCEEDED')
|
74 | expect(executionDescription.ctx.upsertedPerson.createdBy).to.eql(test.userEmail)
|
75 | })
|
76 | }
|
77 | })
|
78 |
|
79 | describe('check execution table', () => {
|
80 | for (const test of tests) {
|
81 | it(test.title, async () => {
|
82 | const execution = await storage.models.tymly_execution.findOne({ where: { executionName: { equals: test.execName } } })
|
83 |
|
84 | expect(execution.createdBy).to.eql(test.userEmail)
|
85 | expect(execution.modifiedBy).to.eql(test.userEmail)
|
86 | })
|
87 | }
|
88 | })
|
89 | })
|
90 | }
|
91 |
|
92 | const combination = [
|
93 | {
|
94 | title: 'long wait, upsert and fetch',
|
95 | person: {
|
96 | employeeNo: '1002',
|
97 | firstName: 'Raymond',
|
98 | lastName: 'Chandler'
|
99 | },
|
100 | stateMachine: LONG_WAIT_AND_UPSERT_STATE_MACHINE,
|
101 | userId: 'SuperSlow',
|
102 | userEmail: 'super@slow.com'
|
103 | },
|
104 | {
|
105 | title: 'wait, upsert and fetch',
|
106 | person: {
|
107 | employeeNo: '1001',
|
108 | firstName: 'Dashiell',
|
109 | lastName: 'Hammett'
|
110 | },
|
111 | stateMachine: WAIT_AND_UPSERT_STATE_MACHINE,
|
112 | userId: 'Slow',
|
113 | userEmail: 'snail@slow.com'
|
114 | },
|
115 | {
|
116 | title: 'upsert and fetch',
|
117 | person: {
|
118 | employeeNo: '1000',
|
119 | firstName: 'Jim',
|
120 | lastName: 'Thompson'
|
121 | },
|
122 | stateMachine: UPSERT_STATE_MACHINE,
|
123 | userId: 'Speedy',
|
124 | userEmail: 'hare@tortoise.com'
|
125 | }
|
126 | ]
|
127 |
|
128 | const speedyspeedy = []
|
129 | for (let i = 0; i !== 500; ++i) {
|
130 | speedyspeedy.push(
|
131 | {
|
132 | title: `${i} upsert and fetch`,
|
133 | person: {
|
134 | employeeNo: `${2000 + i}`
|
135 | },
|
136 | stateMachine: UPSERT_STATE_MACHINE,
|
137 | userId: `Speedy-${i}`,
|
138 | userEmail: `user-email-${i}@domain-${i}.test`
|
139 | }
|
140 | )
|
141 | }
|
142 |
|
143 | testBatch('Different speeds', combination)
|
144 | testBatch('All quick', speedyspeedy)
|
145 |
|
146 | describe('shutdown', () => {
|
147 | it('shutdown Tymly', async () => {
|
148 | await tymlyService.shutdown()
|
149 | })
|
150 | })
|
151 | })
|