1 |
|
2 |
|
3 | const tymly = require('./../lib')
|
4 | const path = require('path')
|
5 | const chai = require('chai')
|
6 | const chaiSubset = require('chai-subset')
|
7 | chai.use(chaiSubset)
|
8 | const expect = chai.expect
|
9 |
|
10 | const UNIQUE_KEY = 'tymlyTest_findByUniqueKey_1_0'
|
11 | const COMPOSITE_KEY = 'tymlyTest_findByCompositeKey_1_0'
|
12 |
|
13 | describe('FindById State Resource', function () {
|
14 | this.timeout(process.env.TIMEOUT || 5000)
|
15 | let tymlyService, statebox
|
16 |
|
17 | before('boot tymly', async () => {
|
18 | const tymlyServices = await tymly.boot({
|
19 | blueprintPaths: [
|
20 | path.resolve(__dirname, './fixtures/blueprints/find-by-id-blueprint')
|
21 | ]
|
22 | })
|
23 |
|
24 | tymlyService = tymlyServices.tymly
|
25 | statebox = tymlyServices.statebox
|
26 | })
|
27 |
|
28 | it('find by unique key', async () => {
|
29 | const executionDescription = await statebox.startExecution(
|
30 | { id: '101' },
|
31 | UNIQUE_KEY,
|
32 | {
|
33 | sendResponse: 'COMPLETE'
|
34 | }
|
35 | )
|
36 |
|
37 | expect(executionDescription.ctx.found).to.containSubset({
|
38 | id: '101',
|
39 | name: 'Billy',
|
40 | animal: 'Dog'
|
41 | })
|
42 | })
|
43 |
|
44 | it('find by unique key, passing array', async () => {
|
45 | const executionDescription = await statebox.startExecution(
|
46 | { id: ['101'] },
|
47 | UNIQUE_KEY,
|
48 | {
|
49 | sendResponse: 'COMPLETE'
|
50 | }
|
51 | )
|
52 |
|
53 | expect(executionDescription.ctx.found).to.containSubset({
|
54 | id: '101',
|
55 | name: 'Billy',
|
56 | animal: 'Dog'
|
57 | })
|
58 | })
|
59 |
|
60 | it('find by composite key, passing array', async () => {
|
61 | const executionDescription = await statebox.startExecution(
|
62 | { key: ['Billy', 'Dog'] },
|
63 | COMPOSITE_KEY,
|
64 | {
|
65 | sendResponse: 'COMPLETE'
|
66 | }
|
67 | )
|
68 |
|
69 | expect(executionDescription.ctx.found).to.containSubset({
|
70 | name: 'Billy',
|
71 | animal: 'Dog',
|
72 | colour: 'orange'
|
73 | })
|
74 | })
|
75 |
|
76 | it('find by composite key', async () => {
|
77 | const executionDescription = await statebox.startExecution(
|
78 | { key: { name: 'Billy', animal: 'Dog' } },
|
79 | COMPOSITE_KEY,
|
80 | {
|
81 | sendResponse: 'COMPLETE'
|
82 | }
|
83 | )
|
84 |
|
85 | expect(executionDescription.ctx.found).to.containSubset({
|
86 | name: 'Billy',
|
87 | animal: 'Dog',
|
88 | colour: 'orange'
|
89 | })
|
90 | })
|
91 |
|
92 | after('shutdown Tymly', async () => {
|
93 | await tymlyService.shutdown()
|
94 | })
|
95 | })
|