Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: tests for get current/next sequence value state resources
- Loading branch information
Showing
7 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
test/fixtures/blueprints/sequence-blueprint/blueprint.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
|
||
"namespace": "tymlyTest", | ||
"name": "sequence", | ||
"version": "1.0", | ||
"label": "People", | ||
"author": "Jas Bahra", | ||
"organisation": "Tymlys", | ||
"description": "An example Tymly Blueprint to test sequence state resources.", | ||
"categories": ["test"] | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/blueprints/sequence-blueprint/pg-scripts/create-sequence.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE SCHEMA IF NOT EXISTS tymly_test; | ||
|
||
CREATE SEQUENCE IF NOT EXISTS tymly_test.ticket_id_seq; |
20 changes: 20 additions & 0 deletions
20
...blueprints/sequence-blueprint/state-machines/find-current-sequence-value-with-prefix.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "FindCurrentSequenceValue", | ||
"version": "1.0", | ||
"StartAt": "FindCurrentSequenceValue", | ||
"States": { | ||
"FindCurrentSequenceValue": { | ||
"Type": "Task", | ||
"Resource": "module:getCurrentValueFromSequence", | ||
"ResourceConfig": { | ||
"namespace": "tymlyTest", | ||
"id": "ticketIdSeq", | ||
"prefix": "ABC" | ||
}, | ||
"ResultSelector": { | ||
"ticketId.$": "$.value" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
test/fixtures/blueprints/sequence-blueprint/state-machines/find-current-sequence-value.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "FindCurrentSequenceValue", | ||
"version": "1.0", | ||
"StartAt": "FindCurrentSequenceValue", | ||
"States": { | ||
"FindCurrentSequenceValue": { | ||
"Type": "Task", | ||
"Resource": "module:getCurrentValueFromSequence", | ||
"ResourceConfig": { | ||
"namespace": "tymlyTest", | ||
"id": "ticketIdSeq" | ||
}, | ||
"ResultSelector": { | ||
"ticketId.$": "$.value" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...es/blueprints/sequence-blueprint/state-machines/find-next-sequence-value-with-prefix.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "FindNextSequenceValue", | ||
"version": "1.0", | ||
"StartAt": "FindNextSequenceValue", | ||
"States": { | ||
"FindNextSequenceValue": { | ||
"Type": "Task", | ||
"Resource": "module:getNextValueFromSequence", | ||
"ResourceConfig": { | ||
"namespace": "tymlyTest", | ||
"id": "ticketIdSeq", | ||
"prefix": "XYZ" | ||
}, | ||
"ResultSelector": { | ||
"ticketId.$": "$.value" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
test/fixtures/blueprints/sequence-blueprint/state-machines/find-next-sequence-value.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "FindNextSequenceValue", | ||
"version": "1.0", | ||
"StartAt": "FindNextSequenceValue", | ||
"States": { | ||
"FindNextSequenceValue": { | ||
"Type": "Task", | ||
"Resource": "module:getNextValueFromSequence", | ||
"ResourceConfig": { | ||
"namespace": "tymlyTest", | ||
"id": "ticketIdSeq" | ||
}, | ||
"ResultSelector": { | ||
"ticketId.$": "$.value" | ||
}, | ||
"End": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* eslint-env mocha */ | ||
|
||
const tymly = require('@wmfs/tymly') | ||
const path = require('path') | ||
const chai = require('chai') | ||
const chaiSubset = require('chai-subset') | ||
const sqlScriptRunner = require('./fixtures/sql-script-runner') | ||
chai.use(chaiSubset) | ||
const expect = chai.expect | ||
|
||
describe('Sequence State Resources', function () { | ||
this.timeout(process.env.TIMEOUT || 5000) | ||
let tymlyService, client, statebox | ||
|
||
before(function () { | ||
if (process.env.PG_CONNECTION_STRING && !/^postgres:\/\/[^:]+:[^@]+@(?:localhost|127\.0\.0\.1).*$/.test(process.env.PG_CONNECTION_STRING)) { | ||
console.log(`Skipping tests due to unsafe PG_CONNECTION_STRING value (${process.env.PG_CONNECTION_STRING})`) | ||
this.skip() | ||
} | ||
}) | ||
|
||
before('create some tymly services', async () => { | ||
const tymlyServices = await tymly.boot( | ||
{ | ||
blueprintPaths: [ | ||
path.resolve(__dirname, './fixtures/blueprints/sequence-blueprint') | ||
], | ||
pluginPaths: [ | ||
path.resolve(__dirname, './../lib') | ||
], | ||
config: {} | ||
} | ||
) | ||
|
||
tymlyService = tymlyServices.tymly | ||
client = tymlyServices.storage.client | ||
statebox = tymlyServices.statebox | ||
}) | ||
|
||
it('find current sequence value of 1', async () => { | ||
const executionDescription = await statebox.startExecution( | ||
{}, | ||
"tymlyTest_findCurrentSequenceValue_1_0", | ||
{ | ||
sendResponse: 'COMPLETE' | ||
} | ||
) | ||
|
||
expect(executionDescription.ctx).to.containSubset({ | ||
ticketId: '1' | ||
}) | ||
}) | ||
|
||
it('find next sequence value of 1', async () => { | ||
const executionDescription = await statebox.startExecution( | ||
{}, | ||
"tymlyTest_findNextSequenceValue_1_0", | ||
{ | ||
sendResponse: 'COMPLETE' | ||
} | ||
) | ||
|
||
expect(executionDescription.ctx).to.containSubset({ | ||
ticketId: '1' | ||
}) | ||
}) | ||
|
||
it('find next sequence value of 2', async () => { | ||
const executionDescription = await statebox.startExecution( | ||
{}, | ||
"tymlyTest_findNextSequenceValue_1_0", | ||
{ | ||
sendResponse: 'COMPLETE' | ||
} | ||
) | ||
|
||
expect(executionDescription.ctx).to.containSubset({ | ||
ticketId: '2' | ||
}) | ||
}) | ||
|
||
it('find (prefixed) current sequence value of ABC2', async () => { | ||
const executionDescription = await statebox.startExecution( | ||
{}, | ||
"tymlyTest_findCurrentSequenceValueWithPrefix_1_0", | ||
{ | ||
sendResponse: 'COMPLETE' | ||
} | ||
) | ||
|
||
expect(executionDescription.ctx).to.containSubset({ | ||
ticketId: 'ABC2' | ||
}) | ||
}) | ||
|
||
it('find (prefixed) next sequence value of XYZ3', async () => { | ||
const executionDescription = await statebox.startExecution( | ||
{}, | ||
"tymlyTest_findNextSequenceValueWithPrefix_1_0", | ||
{ | ||
sendResponse: 'COMPLETE' | ||
} | ||
) | ||
|
||
expect(executionDescription.ctx).to.containSubset({ | ||
ticketId: 'XYZ3' | ||
}) | ||
}) | ||
|
||
after('uninstall test schemas', async () => { | ||
await sqlScriptRunner.uninstall(client) | ||
}) | ||
|
||
after('shutdown Tymly', async () => { | ||
await tymlyService.shutdown() | ||
}) | ||
}) |