UNPKG

1.54 kBJavaScriptView Raw
1/* eslint-env mocha */
2
3const path = require('path')
4const expect = require('chai').expect
5const tymly = require('../lib')
6const moment = require('moment')
7
8const TestTimestamp = moment([2000, 2, 28, 22, 35, 0]).local()
9const TestTimestampString = `${TestTimestamp}`
10
11const timestampStateMachine = 'tymlyTest_timestamp_1_0'
12
13describe('Timestamp state resources', function () {
14 this.timeout(process.env.TIMEOUT || 5000)
15
16 let tymlyService
17 let statebox
18
19 it('boot Tymly', function (done) {
20 tymly.boot(
21 {
22 blueprintPaths: [
23 path.resolve(__dirname, './fixtures/blueprints/timestamp-blueprint')
24 ],
25 pluginPaths: [
26 path.resolve(__dirname, '../node_modules/@wmfs/tymly-test-helpers/plugins/allow-everything-rbac-plugin')
27 ]
28 },
29 function (err, tymlyServices) {
30 if (err) return done(err)
31 tymlyService = tymlyServices.tymly
32 statebox = tymlyServices.statebox
33
34 tymlyServices.timestamp.timeProvider = {
35 now () {
36 return TestTimestamp
37 }
38 } // debug provider
39
40 done()
41 }
42 )
43 })
44
45 it('run the state machine to get a timestamp', async () => {
46 const execDesc = await statebox.startExecution(
47 { },
48 timestampStateMachine,
49 { sendResponse: 'COMPLETE' }
50 )
51 expect(execDesc.ctx.timestamp).to.eql(TestTimestamp)
52 expect(execDesc.ctx.timestamp.toString()).to.eql(TestTimestampString)
53 })
54
55 it('shutdown Tymly', async () => {
56 await tymlyService.shutdown()
57 })
58})