1 |
|
2 |
|
3 | 'use strict'
|
4 |
|
5 | const expect = require('chai').expect
|
6 | const tymly = require('@wmfs/tymly')
|
7 | const path = require('path')
|
8 | const process = require('process')
|
9 | const sqlScriptRunner = require('./fixtures/sql-script-runner.js')
|
10 |
|
11 | describe('tymly-solr-plugin add docs resource tests', function () {
|
12 | this.timeout(process.env.TIMEOUT || 5000)
|
13 |
|
14 | let tymlyService, statebox, client
|
15 |
|
16 | before(function () {
|
17 | if (process.env.PG_CONNECTION_STRING && !/^postgres:\/\/[^:]+:[^@]+@(?:localhost|127\.0\.0\.1).*$/.test(process.env.PG_CONNECTION_STRING)) {
|
18 | console.log(`Skipping tests due to unsafe PG_CONNECTION_STRING value (${process.env.PG_CONNECTION_STRING})`)
|
19 | this.skip()
|
20 | }
|
21 | })
|
22 |
|
23 | it('should run the tymly services', function (done) {
|
24 | tymly.boot(
|
25 | {
|
26 | pluginPaths: [
|
27 | path.resolve(__dirname, './../lib'),
|
28 | require.resolve('@wmfs/tymly-pg-plugin'),
|
29 | require.resolve('@wmfs/tymly-cardscript-plugin'),
|
30 | require.resolve('@wmfs/tymly-rbac-plugin')
|
31 | ],
|
32 | blueprintPaths: [
|
33 | path.resolve(__dirname, './fixtures/incident-blueprint')
|
34 | ]
|
35 | },
|
36 | function (err, tymlyServices) {
|
37 | expect(err).to.eql(null)
|
38 | tymlyService = tymlyServices.tymly
|
39 | statebox = tymlyServices.statebox
|
40 | client = tymlyServices.storage.client
|
41 | done()
|
42 | }
|
43 | )
|
44 | })
|
45 |
|
46 | if (process.env.SOLR_URL && process.env.SOLR_PATH && process.env.SOLR_PORT && process.env.SOLR_HOST) {
|
47 | it('should create test resources', function (done) {
|
48 | client.query(`INSERT INTO tymly_test.incident (inc_no, description) VALUES (1, 'A bad incident');`, (err) => {
|
49 | done(err)
|
50 | })
|
51 | })
|
52 |
|
53 | it('should ensure the record to be inserted isn\'t already there', done => {
|
54 | statebox.startExecution(
|
55 | {
|
56 | query: 'A bad incident',
|
57 | offset: 0,
|
58 | limit: 10
|
59 | },
|
60 | 'tymlyTest_search_1_0',
|
61 | {
|
62 | sendResponse: 'COMPLETE',
|
63 | userId: 'test-user-1'
|
64 | },
|
65 | function (err, executionDescription) {
|
66 | expect(err).to.eql(null)
|
67 | console.log(JSON.stringify(executionDescription, null, 2))
|
68 | expect(executionDescription.ctx.searchResults.totalHits).to.eql(0)
|
69 | done(err)
|
70 | }
|
71 | )
|
72 | })
|
73 |
|
74 | it('should get a record and try to add it', function (done) {
|
75 | statebox.startExecution(
|
76 | {
|
77 | id: 1
|
78 | },
|
79 | 'tymlyTest_addDocs_1_0',
|
80 | {
|
81 | sendResponse: 'COMPLETE',
|
82 | userId: 'test-user-1'
|
83 | },
|
84 | function (err, executionDescription) {
|
85 | expect(err).to.eql(null)
|
86 | expect(executionDescription.currentStateName).to.eql('AddDocs')
|
87 | expect(executionDescription.currentResource).to.eql('module:addDocs')
|
88 | expect(executionDescription.status).to.eql('SUCCEEDED')
|
89 | done(err)
|
90 | }
|
91 | )
|
92 | })
|
93 |
|
94 | it('should ensure the record was added', done => {
|
95 | statebox.startExecution(
|
96 | {
|
97 | query: 'A bad incident',
|
98 | offset: 0,
|
99 | limit: 10
|
100 | },
|
101 | 'tymlyTest_search_1_0',
|
102 | {
|
103 | sendResponse: 'COMPLETE',
|
104 | userId: 'test-user-1'
|
105 | },
|
106 | function (err, executionDescription) {
|
107 | expect(err).to.eql(null)
|
108 | console.log(JSON.stringify(executionDescription, null, 2))
|
109 | expect(executionDescription.ctx.searchResults.totalHits).to.eql(1)
|
110 | done(err)
|
111 | }
|
112 | )
|
113 | })
|
114 |
|
115 | it('should remove the test doc', done => {
|
116 | statebox.startExecution(
|
117 | {},
|
118 | 'tymlyTest_removeDocs_1_0',
|
119 | {
|
120 | sendResponse: 'COMPLETE',
|
121 | userId: 'test-user-1'
|
122 | },
|
123 | function (err, executionDescription) {
|
124 | expect(err).to.eql(null)
|
125 | done(err)
|
126 | }
|
127 | )
|
128 | })
|
129 |
|
130 | it('should ensure the record has been removed', done => {
|
131 | statebox.startExecution(
|
132 | {
|
133 | offset: 0,
|
134 | limit: 10
|
135 | },
|
136 | 'tymlyTest_search_1_0',
|
137 | {
|
138 | sendResponse: 'COMPLETE',
|
139 | userId: 'test-user-1'
|
140 | },
|
141 | function (err, executionDescription) {
|
142 | expect(err).to.eql(null)
|
143 | expect(executionDescription.ctx.searchResults.totalHits).to.eql(0)
|
144 | done(err)
|
145 | }
|
146 | )
|
147 | })
|
148 |
|
149 | it('should wait a while', (done) => {
|
150 | setTimeout(done, 4900)
|
151 | })
|
152 | }
|
153 |
|
154 | it('should cleanup test resources', function (done) {
|
155 | sqlScriptRunner(
|
156 | './db-scripts/cleanup.sql',
|
157 | client,
|
158 | function (err) {
|
159 | expect(err).to.equal(null)
|
160 | if (err) {
|
161 | done(err)
|
162 | } else {
|
163 | done()
|
164 | }
|
165 | }
|
166 | )
|
167 | })
|
168 |
|
169 | it('should shutdown Tymly', async () => {
|
170 | await tymlyService.shutdown()
|
171 | })
|
172 | })
|