UNPKG

2.91 kBJavaScriptView Raw
1/* eslint-env mocha */
2const expect = require('chai').expect
3const tymly = require('@wmfs/tymly')
4const path = require('path')
5const process = require('process')
6const sqlScriptRunner = require('./fixtures/sql-script-runner.js')
7
8const reindexTests = [
9 {
10 name: 'delta reindex',
11 stateName: 'DeltaReindex',
12 resource: 'module:deltaReindex',
13 stateMachine: 'tymlyTest_deltaReindex_1_0'
14 },
15 {
16 name: 'full reindex',
17 stateName: 'FullReindex',
18 resource: 'module:fullReindex',
19 stateMachine: 'tymlyTest_fullReindex_1_0'
20 }
21]
22
23for (const test of reindexTests) {
24 describe(`tymly-solr-plugin ${test.name} tests`, function () {
25 this.timeout(process.env.TIMEOUT || 5000)
26
27 let statebox, tymlyService, client
28
29 before(function () {
30 if (process.env.PG_CONNECTION_STRING && !/^postgres:\/\/[^:]+:[^@]+@(?:localhost|127\.0\.0\.1).*$/.test(process.env.PG_CONNECTION_STRING)) {
31 console.log(`Skipping tests due to unsafe PG_CONNECTION_STRING value (${process.env.PG_CONNECTION_STRING})`)
32 this.skip()
33 }
34 })
35
36 it('should run the tymly services', function (done) {
37 tymly.boot(
38 {
39 pluginPaths: [
40 path.resolve(__dirname, './../lib'),
41 require.resolve('@wmfs/tymly-pg-plugin')
42 ],
43 blueprintPaths: [
44 path.resolve(__dirname, './fixtures/school-blueprint')
45 ],
46 config: {
47 solrSchemaFields: [
48 'id',
49 'actorName',
50 'characterName'
51 ]
52 }
53 },
54 function (err, tymlyServices) {
55 expect(err).to.eql(null)
56 tymlyService = tymlyServices.tymly
57 statebox = tymlyServices.statebox
58 client = tymlyServices.storage.client
59 done()
60 }
61 )
62 })
63
64 it(`should start the ${test.stateMachine} state machine`, function (done) {
65 statebox.startExecution(
66 {}, // input
67 test.stateMachine, // state machine name
68 {
69 sendResponse: 'COMPLETE'
70 }, // options
71 function (err, executionDescription) {
72 try {
73 expect(err).to.eql(null)
74 expect(executionDescription.currentStateName).to.eql(test.stateName)
75 expect(executionDescription.currentResource).to.eql(test.resource)
76 expect(executionDescription.stateMachineName).to.eql(test.stateMachine)
77 expect(executionDescription.status).to.eql('SUCCEEDED')
78 done()
79 } catch (e) {
80 done(e)
81 }
82 }
83 )
84 })
85
86 it('should cleanup test resources', (done) => {
87 sqlScriptRunner(
88 './db-scripts/cleanup.sql',
89 client,
90 (err) => {
91 expect(err).to.equal(null)
92 done(err)
93 }
94 )
95 })
96
97 it('should shutdown Tymly', async () => {
98 await tymlyService.shutdown()
99 })
100 })
101}