UNPKG

@wmfs/tymly-pg-plugin

Version:

Replace Tymly's out-the-box memory storage with PostgreSQL

104 lines (90 loc) 2.4 kB
/* eslint-env mocha */ const tymly = require('@wmfs/tymly') const path = require('path') const chai = require('chai') const chaiSubset = require('chai-subset') chai.use(chaiSubset) const expect = chai.expect const UNIQUE_KEY = 'tymlyTest_findByUniqueKey_1_0' const COMPOSITE_KEY = 'tymlyTest_findByCompositeKey_1_0' describe('FindById State Resource', function () { this.timeout(process.env.TIMEOUT || 5000) let tymlyService, statebox before('boot tymly', done => { tymly.boot( { blueprintPaths: [ path.resolve(__dirname, './fixtures/blueprints/find-by-id-blueprint') ], pluginPaths: [ path.resolve(__dirname, './../lib') ] }, (err, tymlyServices) => { expect(err).to.eql(null) tymlyService = tymlyServices.tymly statebox = tymlyServices.statebox done() } ) }) it('find by unique key', async () => { const executionDescription = await statebox.startExecution( { id: '101' }, UNIQUE_KEY, { sendResponse: 'COMPLETE' } ) expect(executionDescription.ctx.found).to.containSubset({ id: '101', name: 'Billy', animal: 'Dog' }) }) it('find by unique key, passing array', async () => { const executionDescription = await statebox.startExecution( { id: ['101'] }, UNIQUE_KEY, { sendResponse: 'COMPLETE' } ) expect(executionDescription.ctx.found).to.containSubset({ id: '101', name: 'Billy', animal: 'Dog' }) }) it('find by composite key, passing array', async () => { const executionDescription = await statebox.startExecution( { key: ['Billy', 'Dog'] }, COMPOSITE_KEY, { sendResponse: 'COMPLETE' } ) expect(executionDescription.ctx.found).to.containSubset({ name: 'Billy', animal: 'Dog', colour: 'orange' }) }) it('find by composite key', async () => { const executionDescription = await statebox.startExecution( { key: { name: 'Billy', animal: 'Dog' } }, COMPOSITE_KEY, { sendResponse: 'COMPLETE' } ) expect(executionDescription.ctx.found).to.containSubset({ name: 'Billy', animal: 'Dog', colour: 'orange' }) }) after('shutdown Tymly', async () => { await tymlyService.shutdown() }) })