Skip to content

Commit

Permalink
test: tests for get current/next sequence value state resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-b committed Oct 24, 2023
1 parent 39c20c7 commit 27afa53
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/fixtures/blueprints/sequence-blueprint/blueprint.json
@@ -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"]
}
@@ -0,0 +1,3 @@
CREATE SCHEMA IF NOT EXISTS tymly_test;

CREATE SEQUENCE IF NOT EXISTS tymly_test.ticket_id_seq;
@@ -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
}
}
}
@@ -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
}
}
}
@@ -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
}
}
}
@@ -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
}
}
}
117 changes: 117 additions & 0 deletions test/sequence-spec.js
@@ -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()
})
})

0 comments on commit 27afa53

Please sign in to comment.