New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@wmfs/tymly-pg-plugin

Package Overview
Dependencies
Maintainers
1
Versions
329
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wmfs/tymly-pg-plugin - npm Package Compare versions

Comparing version 1.195.2 to 1.195.3

test/pg-storage-via-state-machines.js

6

lib/components/services/storage/generate-upsert-statement.js

@@ -14,8 +14,4 @@ 'use strict'

const rowCount = object.data.length
const columnNames = []
const columnNames = object.propertyNames.map(pn => _.snakeCase(pn))
for (const pn of object.propertyNames) {
columnNames.push(_.snakeCase(pn))
}
let statement = `INSERT INTO ${model.fullTableName} (${columnNames.join(', ')}) VALUES `

@@ -22,0 +18,0 @@ for (let row = 1; row <= rowCount; row++) {

@@ -8,3 +8,2 @@ 'use strict'

const process = require('process')
const async = require('async')

@@ -76,3 +75,3 @@ const relationize = require('@wmfs/relationize')

async _installExtension () {
_installExtension () {
return this.client.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";')

@@ -157,68 +156,42 @@ }

_insertMultipleSeedData (seedDataArray, messages) {
return new Promise((resolve, reject) => {
this._doInsertMultipleSeedData(seedDataArray, messages, (err) => {
if (err) {
return reject(err)
}
resolve()
})
})
} // insertMultipleSeedData
async _insertMultipleSeedData (seedDataArray, messages) {
if (!seedDataArray) {
infoMessage(messages, 'No seed data to insert')
return
}
_doInsertMultipleSeedData (seedDataArray, messages, callback) {
const _this = this
if (seedDataArray) {
infoMessage(messages, 'Loading seed data:')
async.eachSeries(
seedDataArray,
(seedData, cb) => {
const name = seedData.namespace + '_' + seedData.name
const model = _this.models[name]
if (model) {
detailMessage(messages, name)
infoMessage(messages, 'Loading seed data:')
// generate upsert sql statement
const sql = generateUpsertStatement(model, seedData)
debug('load', name, 'seed-data sql: ', sql)
for (const seedData of Object.values(seedDataArray)) {
const name = `${seedData.namespace}_${seedData.name}`
const model = this.models[name]
if (model) {
await this._insertModelSeedData(name, model, seedData, messages)
} else {
detailMessage(messages, `WARNING: seed data found for model ${name}, but no such model was found`)
}
} // for ...
} // _insertMultipleSeedData
// generate a single array of parameters which each
// correspond with a placeholder in the upsert sql statement
let params = []
_.forEach(seedData.data, (row) => {
params = params.concat(row)
})
debug('load', name, 'seed-data params: ', params)
_insertModelSeedData (name, model, seedData, messages) {
detailMessage(messages, name)
_this.client.run(
[{
sql: sql,
params: params
}],
function (err) {
if (err) {
cb(err)
} else {
cb(null)
}
}
)
} else {
detailMessage(messages, `WARNING: seed data found for model ${name}, but no such model was found`)
cb(null)
}
},
(err) => {
if (err) {
callback(err)
} else {
callback(null)
}
})
} else {
infoMessage(messages, 'No seed data to insert')
callback(null)
}
} // _doInsertMultipleSeedData
// generate upsert sql statement
const sql = generateUpsertStatement(model, seedData)
debug('load', name, 'seed-data sql: ', sql)
// generate a single array of parameters which each
// correspond with a placeholder in the upsert sql statement
const params = []
seedData.data.forEach(row => params.push(...row))
debug('load', name, 'seed-data params: ', params)
return this.client.run(
[{
sql: sql,
params: params
}]
)
} // _insertModelSeedData
_runScripts (scripts, messages) {

@@ -225,0 +198,0 @@ infoMessage(messages, 'Scripts:')

{
"name": "@wmfs/tymly-pg-plugin",
"version": "1.195.2",
"version": "1.195.3",
"description": "Replace Tymly's out-the-box memory storage with PostgreSQL",

@@ -24,4 +24,2 @@ "author": "West Midlands Fire Service",

"dependencies": {
"async": "3.2.0",
"boom": "7.3.0",
"debug": "4.1.1",

@@ -46,6 +44,6 @@ "dottie": "2.0.2",

"cz-conventional-changelog": "3.1.0",
"mocha": "7.1.1",
"mocha": "7.1.2",
"nyc": "15.0.1",
"rimraf": "3.0.2",
"semantic-release": "17.0.6",
"semantic-release": "17.0.7",
"standard": "14.3.3",

@@ -55,3 +53,3 @@ "@semantic-release/changelog": "5.0.1",

"@semantic-release/exec": "5.0.0",
"@wmfs/tymly": "1.135.1"
"@wmfs/tymly": "1.137.0"
},

@@ -58,0 +56,0 @@ "scripts": {

{
"name": "pg",
"version": "1.195.2",
"version": "1.195.3",
"label": "PG",

@@ -5,0 +5,0 @@ "author": "Tim Needham",

@@ -12,3 +12,3 @@ /* eslint-env mocha */

describe('Testing functionality as a state-resource', function () {
describe('Multicopy state-resource tests', function () {
this.timeout(process.env.TIMEOUT || 5000)

@@ -28,4 +28,4 @@ let client

it('should create some tymly services to test PostgreSQL storage', function (done) {
tymly.boot(
it('boot tymly', async () => {
const tymlyServices = await tymly.boot(
{

@@ -41,14 +41,11 @@ pluginPaths: [

config: {}
},
function (err, tymlyServices) {
expect(err).to.eql(null)
tymlyService = tymlyServices.tymly
client = tymlyServices.storage.client
statebox = tymlyServices.statebox
done()
}
)
tymlyService = tymlyServices.tymly
client = tymlyServices.storage.client
statebox = tymlyServices.statebox
})
it('should start a multicopy execution', async () => {
it('start multicopy execution', async () => {
const executionDescription = await statebox.startExecution(

@@ -65,3 +62,3 @@ {

it('should successfully complete a multicopy execution', async () => {
it('complete multicopy execution', async () => {
const executionDescription = await statebox.waitUntilStoppedRunning(executionName)

@@ -74,3 +71,3 @@

it('should find the correct data in the correct database tables (meat)', async () => {
it('verify data in "meat" table', async () => {
const result = await client.query('select * from food_test.meat')

@@ -87,3 +84,3 @@

it('should find the correct data in the correct database tables (veg)', async () => {
it('verify data in "veg" table', async () => {
const result = await client.query('select * from food_test.veg')

@@ -100,9 +97,9 @@

it('should clean up DB env', async () => {
after('clean up DB env', async () => {
await sqlScriptRunner.cleanup(client)
})
it('should shutdown Tymly', async () => {
after('shutdown Tymly', async () => {
await tymlyService.shutdown()
})
})

@@ -52,6 +52,5 @@ /* eslint-env mocha */

it('close database connections', function (done) {
after('close database connections', () => {
client.end()
done()
})
})

@@ -12,3 +12,3 @@ /* eslint-env mocha */

describe('PG storage tests', function () {
describe('PG storage service tests', function () {
this.timeout(process.env.TIMEOUT || 5000)

@@ -31,4 +31,4 @@

describe('start up', () => {
it('should create some out-the-box tymly services to test PG storage state-machines', (done) => {
tymly.boot(
it('boot tymly', async () => {
const tymlyServices = await tymly.boot(
{

@@ -43,21 +43,17 @@ pluginPaths: [

]
},
function (err, tymlyServices) {
expect(err).to.eql(null)
tymlyService = tymlyServices.tymly
storage = tymlyServices.storage
client = tymlyServices.storage.client
const models = tymlyServices.storage.models
people = models.tymlyTest_people
planets = models.tymlyTest_planets
star = models.tymlyTest_star
star.findById('Arcturus')
.then(seededStar => expect(seededStar.name).to.eql('Arcturus'))
.then(() => planets.findById('Mercury'))
.then(seededPlanet => expect(seededPlanet.name).to.eql('Mercury'))
.then(() => done())
.catch(err => done(err))
}
)
tymlyService = tymlyServices.tymly
storage = tymlyServices.storage
client = tymlyServices.storage.client
const models = tymlyServices.storage.models
people = models.tymlyTest_people
planets = models.tymlyTest_planets
star = models.tymlyTest_star
const seededStar = await star.findById('Arcturus')
expect(seededStar.name).to.eql('Arcturus')
const seededPlanet = await planets.findById('Mercury')
expect(seededPlanet.name).to.eql('Mercury')
})

@@ -67,4 +63,4 @@ })

describe('single table', () => {
it('should create a new person', function (done) {
people.create(
it('create a new person', async () => {
const idProperties = await people.create(
{

@@ -76,20 +72,14 @@ employeeNo: '1',

},
{},
function (err, idProperties) {
expect(err).to.equal(null)
expect(idProperties).to.eql(
{
idProperties:
{
employeeNo: '1'
}
}
)
done()
{}
)
expect(idProperties).to.eql({
idProperties: {
employeeNo: '1'
}
)
})
})
it('should create multiple new people', function (done) {
people.create(
it('create multiple new people', async () => {
await people.create(
[

@@ -119,33 +109,12 @@ {

}
],
{},
function (err) {
expect(err).to.equal(null)
done()
}
{}
)
})
it('should fail creating a new person with an already-used primary key', function (done) {
people.create(
{
employeeNo: '1',
firstName: 'Ned',
lastName: 'Flanders',
age: 60
},
{},
function (err) {
expect(err).to.not.equal(null)
done()
}
)
})
it('should fail creating new people with an already-used primary key', function (done) {
people.create(
[
it('fail when primary key already used', async () => {
try {
await people.create(
{
employeeNo: '6',
employeeNo: '1',
firstName: 'Ned',

@@ -155,41 +124,45 @@ lastName: 'Flanders',

},
{
employeeNo: '2',
firstName: 'Maude',
lastName: 'Flanders'
}
],
{},
function (err) {
expect(err).to.not.equal(null)
done()
}
)
{}
)
} catch (err) {
return
}
expect.fail('Should have thrown')
})
it('should find a person via primary key', function (done) {
people.findById(
'3',
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.containSubset(
it('fail creating new people with an already-used primary key', async () => {
try {
await people.create(
[
{
employeeNo: '3',
firstName: 'Lisa',
lastName: 'Simpson',
age: 8
employeeNo: '6',
firstName: 'Ned',
lastName: 'Flanders',
age: 60
},
{
employeeNo: '2',
firstName: 'Maude',
lastName: 'Flanders'
}
)
done()
}
)
],
{}
)
} catch (err) {
return
}
expect.fail('Should have thrown')
})
it("should fail finding a person that's not there", function (done) {
people.findById(
'0',
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.equal(undefined)
done()
it('find a person by primary key', async () => {
const doc = await people.findById(3)
expect(doc).to.containSubset(
{
employeeNo: '3',
firstName: 'Lisa',
lastName: 'Simpson',
age: 8
}

@@ -199,54 +172,56 @@ )

it('should find 5 people, youngest first', function (done) {
people.find(
it('find nothing for an unknown primary key', async () => {
const doc = await people.findById(0)
expect(doc).to.equal(undefined)
})
it('find 5 people, order youngest first', async () => {
const doc = await people.find(
{
orderBy: ['age']
},
function (err, doc) {
expect(err).to.equal(null)
expect(doc[0].age).to.equal(8)
expect(doc[1].age).to.equal(10)
expect(doc[2].age).to.equal(36)
expect(doc[3].age).to.equal(39)
expect(doc).to.containSubset(
[
{
age: 8,
employeeNo: '3',
firstName: 'Lisa',
lastName: 'Simpson'
},
{
age: 10,
employeeNo: '5',
firstName: 'Bart',
lastName: 'Simpson'
},
{
age: 36,
employeeNo: '4',
firstName: 'Marge',
lastName: 'Simpson'
},
{
age: 39,
employeeNo: '1',
firstName: 'Homer',
lastName: 'Simpson'
},
{
employeeNo: '2',
firstName: 'Maggie',
lastName: 'Simpson'
}
]
)
done()
}
)
expect(doc[0].age).to.equal(8)
expect(doc[1].age).to.equal(10)
expect(doc[2].age).to.equal(36)
expect(doc[3].age).to.equal(39)
expect(doc).to.containSubset(
[
{
age: 8,
employeeNo: '3',
firstName: 'Lisa',
lastName: 'Simpson'
},
{
age: 10,
employeeNo: '5',
firstName: 'Bart',
lastName: 'Simpson'
},
{
age: 36,
employeeNo: '4',
firstName: 'Marge',
lastName: 'Simpson'
},
{
age: 39,
employeeNo: '1',
firstName: 'Homer',
lastName: 'Simpson'
},
{
employeeNo: '2',
firstName: 'Maggie',
lastName: 'Simpson'
}
]
)
})
it('should find Bart by name', function (done) {
people.find(
it('find Bart by name', async () => {
const doc = await people.find(
{

@@ -257,24 +232,20 @@ where: {

}
},
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.have.length(1)
expect(doc).to.containSubset(
[
{
age: 10,
employeeNo: '5',
firstName: 'Bart',
lastName: 'Simpson'
}
]
)
done()
}
)
expect(doc).to.have.length(1)
expect(doc).to.containSubset(
[
{
age: 10,
employeeNo: '5',
firstName: 'Bart',
lastName: 'Simpson'
}
]
)
})
it('should find Marge and Homer (offset 2/limit 2)', function (done) {
people.find(
it('find Marge and Homer, (order by/offset 2/limit 2)', async () => {
const doc = await people.find(
{

@@ -284,47 +255,40 @@ orderBy: ['age'],

offset: 2
},
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.have.length(2)
expect(doc[0].employeeNo).to.eql('4')
expect(doc[1].employeeNo).to.eql('1')
expect(doc).to.containSubset(
[
{
employeeNo: '4',
firstName: 'Marge',
lastName: 'Simpson',
age: 36
},
{
employeeNo: '1',
firstName: 'Homer',
lastName: 'Simpson',
age: 39
}
]
)
done()
}
)
expect(doc).to.have.length(2)
expect(doc[0].employeeNo).to.eql('4')
expect(doc[1].employeeNo).to.eql('1')
expect(doc).to.containSubset(
[
{
employeeNo: '4',
firstName: 'Marge',
lastName: 'Simpson',
age: 36
},
{
employeeNo: '1',
firstName: 'Homer',
lastName: 'Simpson',
age: 39
}
]
)
})
it('should get the second youngest known person (Bart)', function (done) {
people.findOne(
it('findOne second youngest known person (orderBy/offset)', async () => {
const doc = await people.findOne(
{
orderBy: ['age'],
offset: 1
},
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.containSubset(
{
age: 10,
employeeNo: '5',
firstName: 'Bart',
lastName: 'Simpson'
}
)
}
)
done()
expect(doc).to.containSubset(
{
age: 10,
employeeNo: '5',
firstName: 'Bart',
lastName: 'Simpson'
}

@@ -334,4 +298,4 @@ )

it('should get one Homer by name', function (done) {
people.findOne(
it('findOne by name', async () => {
const doc = await people.findOne(
{

@@ -342,15 +306,11 @@ where: {

}
},
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.containSubset(
{
age: 39,
employeeNo: '1',
firstName: 'Homer',
lastName: 'Simpson'
}
)
}
)
done()
expect(doc).to.containSubset(
{
age: 39,
employeeNo: '1',
firstName: 'Homer',
lastName: 'Simpson'
}

@@ -360,4 +320,4 @@ )

it("shouldn't get one missing person", function (done) {
people.findOne(
it('findOne return nothing for unknown person', async () => {
const doc = await people.findOne(
{

@@ -368,13 +328,10 @@ where: {

}
},
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.equal(undefined)
done()
}
)
expect(doc).to.equal(undefined)
})
it("should update Maggie's age to 1", function (done) {
people.update(
it("update Maggie's age to 1", async () => {
await people.update(
{

@@ -386,24 +343,15 @@ employeeNo: '2',

},
{},
function (err) {
expect(err).to.equal(null)
done()
}
{}
)
})
it('should find Maggie has an age now', function (done) {
people.findById(
'2',
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.containSubset(
{
employeeNo: '2',
firstName: 'Maggie',
lastName: 'Simpson',
age: 1
}
)
done()
it('Maggie has an age', async () => {
const doc = await people.findById(2)
expect(doc).to.containSubset(
{
employeeNo: '2',
firstName: 'Maggie',
lastName: 'Simpson',
age: 1
}

@@ -413,4 +361,4 @@ )

it('should update Maggie again, but this time without an age', function (done) {
people.update(
it('update Maggie again, this time without an age', async () => {
await people.update(
{

@@ -421,23 +369,14 @@ employeeNo: '2',

},
{},
function (err, doc) {
expect(err).to.equal(null)
done()
}
{}
)
})
it("should find Maggie's age has gone again", function (done) {
people.findById(
'2',
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.containSubset(
{
employeeNo: '2',
firstName: 'Maggie',
lastName: 'Simpson'
}
)
done()
it("Maggie's age has gone again", async () => {
const doc = await people.findById(2)
expect(doc).to.containSubset(
{
employeeNo: '2',
firstName: 'Maggie',
lastName: 'Simpson'
}

@@ -447,25 +386,14 @@ )

it('should delete Maggie/Margaret by via her id', function (done) {
people.destroyById(
'2',
function (err, doc) {
expect(err).to.equal(null)
done()
}
)
it('delete Maggie by id', async () => {
await people.destroyById(2)
})
it('should fail getting a deleted record', function (done) {
people.findById(
'2',
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.equal(undefined)
done()
}
)
it('can not find a deleted record', async () => {
const doc = await people.findById(2)
expect(doc).to.equal(undefined)
})
it('should upsert (insert) a person with an object', function (done) {
people.upsert(
it('upsert (insert) a person', async () => {
const idProperties = await people.upsert(
{

@@ -478,13 +406,10 @@ employeeNo: '4',

},
{},
function (err, idProperties) {
expect(idProperties).to.eql(
{
idProperties: {
employeeNo: '4'
}
}
)
expect(err).to.equal(null)
done()
{}
)
expect(idProperties).to.eql(
{
idProperties: {
employeeNo: '4'
}
}

@@ -494,4 +419,4 @@ )

it('should upsert (insert) a person with an array as an object', function (done) {
people.upsert(
it('upsert (insert) a person with an array subobject', async () => {
const idProperties = await people.upsert(
{

@@ -507,13 +432,10 @@ employeeNo: '4',

},
{},
function (err, idProperties) {
expect(idProperties).to.eql(
{
idProperties: {
employeeNo: '4'
}
}
)
expect(err).to.equal(null)
done()
{}
)
expect(idProperties).to.eql(
{
idProperties: {
employeeNo: '4'
}
}

@@ -523,4 +445,4 @@ )

it('should upsert (insert) Grampa', function (done) {
people.upsert(
it('upsert (insert) Grampa', async () => {
const idProperties = await people.upsert(
{

@@ -532,13 +454,10 @@ employeeNo: '10',

},
{},
function (err, idProperties) {
expect(idProperties).to.eql(
{
idProperties: {
employeeNo: '10'
}
}
)
expect(err).to.equal(null)
done()
{}
)
expect(idProperties).to.eql(
{
idProperties: {
employeeNo: '10'
}
}

@@ -548,16 +467,11 @@ )

it('should find Grampa has been inserted via upsert', function (done) {
people.findById(
'10',
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.containSubset(
{
employeeNo: '10',
firstName: 'Abe',
lastName: 'Simpson',
age: 82
}
)
done()
it('find Grampa by id', async () => {
const doc = await people.findById(10)
expect(doc).to.containSubset(
{
employeeNo: '10',
firstName: 'Abe',
lastName: 'Simpson',
age: 82
}

@@ -567,4 +481,4 @@ )

it('should upsert (update) Grampa', function (done) {
people.upsert(
it('upsert (update) Grampa', async () => {
await people.upsert(
{

@@ -576,24 +490,15 @@ employeeNo: '10',

},
{},
function (err, doc) {
expect(err).to.equal(null)
done()
}
{}
)
})
it('should find Grampa has now been updates via upsert', function (done) {
people.findById(
'10',
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.containSubset(
{
employeeNo: '10',
firstName: 'Abraham',
lastName: 'Simpson',
age: 83
}
)
done()
it('find Grampa by id, verify update', async () => {
const doc = await people.findById(10)
expect(doc).to.containSubset(
{
employeeNo: '10',
firstName: 'Abraham',
lastName: 'Simpson',
age: 83
}

@@ -604,15 +509,10 @@ )

describe('reference data', () => {
it('should find a star (reference table loaded as seed data) via primary key', function (done) {
star.findById(
'Proxima Centauri',
function (err, doc) {
expect(err).to.equal(null)
expect(doc).to.containSubset(
{
name: 'Proxima Centauri',
type: 'Red Dwarf'
}
)
done()
describe('reference table, loaded as seed data', () => {
it('find star via primary key', async () => {
const doc = await star.findById('Proxima Centauri')
expect(doc).to.containSubset(
{
name: 'Proxima Centauri',
type: 'Red Dwarf'
}

@@ -624,4 +524,4 @@ )

describe('related tables', () => {
it('should create mars, with two moons and a few craters', function (done) {
planets.create(
it('create mars, with two moons and a few craters', async () => {
const idProperties = await planets.create(
{

@@ -653,13 +553,10 @@ name: 'mars',

},
{},
function (err, idProperties) {
expect(err).to.equal(null)
expect(idProperties).to.eql(
{
idProperties: {
name: 'mars'
}
}
)
done()
{}
)
expect(idProperties).to.eql(
{
idProperties: {
name: 'mars'
}
}

@@ -666,0 +563,0 @@ )

@@ -33,15 +33,12 @@ /* eslint-env mocha */

it('boot tymly', function (done) {
tymly.boot(
tymlyConfig,
function (err, tymlyServices) {
expect(err).to.eql(null)
tymlyService = tymlyServices.tymly
statebox = tymlyServices.statebox
done()
}
it('boot tymly', async () => {
const tymlyServices = await tymly.boot(
tymlyConfig
)
tymlyService = tymlyServices.tymly
statebox = tymlyServices.statebox
})
it('find cat state machine', function () {
it('find cat state machine', () => {
const stateMachine = statebox.findStateMachineByName(STATE_MACHINE_NAME)

@@ -51,4 +48,4 @@ expect(stateMachine.name).to.eql(STATE_MACHINE_NAME)

it('execute cat state machine', function (done) {
statebox.startExecution(
it('execute cat state machine', async () => {
const executionDescription = await statebox.startExecution(
{

@@ -62,49 +59,34 @@ petName: 'Rupert',

STATE_MACHINE_NAME, // state machine name
{}, // options
function (err, result) {
expect(err).to.eql(null)
rupert = result.executionName
done()
}
{} // options
)
rupert = executionDescription.executionName
})
xit('reboot tymly', function (done) {
tymly.boot(
tymlyConfig,
function (err, tymlyServices) {
expect(err).to.eql(null)
statebox = tymlyServices.statebox
done()
}
xit('reboot tymly', async () => {
const tymlyServices = await tymly.boot(
tymlyConfig
)
statebox = tymlyServices.statebox
})
it('complete Rupert\'s day', function (done) {
statebox.waitUntilStoppedRunning(
rupert,
function (err, executionDescription) {
try {
expect(err).to.eql(null)
expect(executionDescription.status).to.eql('SUCCEEDED')
expect(executionDescription.stateMachineName).to.eql('tymlyTest_aDayInTheLife')
expect(executionDescription.currentStateName).to.eql('Sleeping')
expect(executionDescription.ctx.hoursSinceLastMeal).to.eql(0)
expect(executionDescription.ctx.hoursSinceLastMotion).to.eql(0)
expect(executionDescription.ctx.gender).to.eql('male')
expect(executionDescription.ctx.petDiary).to.be.an('array')
expect(executionDescription.ctx.petDiary[0]).to.equal('Look out, Rupert is waking up!')
expect(executionDescription.ctx.petDiary[2]).to.equal("Rupert is walking... where's he off to?")
expect(executionDescription.ctx.petDiary[6]).to.equal('Shh, Rupert is eating...')
done()
} catch (oops) {
done(oops)
}
}
)
it('complete Rupert\'s day', async () => {
const executionDescription =
await statebox.waitUntilStoppedRunning(rupert)
expect(executionDescription.status).to.eql('SUCCEEDED')
expect(executionDescription.stateMachineName).to.eql('tymlyTest_aDayInTheLife')
expect(executionDescription.currentStateName).to.eql('Sleeping')
expect(executionDescription.ctx.hoursSinceLastMeal).to.eql(0)
expect(executionDescription.ctx.hoursSinceLastMotion).to.eql(0)
expect(executionDescription.ctx.gender).to.eql('male')
expect(executionDescription.ctx.petDiary).to.be.an('array')
expect(executionDescription.ctx.petDiary[0]).to.equal('Look out, Rupert is waking up!')
expect(executionDescription.ctx.petDiary[2]).to.equal("Rupert is walking... where's he off to?")
expect(executionDescription.ctx.petDiary[6]).to.equal('Shh, Rupert is eating...')
})
it('should shutdown Tymly', async () => {
after('shutdown Tymly', async () => {
await tymlyService.shutdown()
})
})

@@ -19,3 +19,3 @@ /* eslint-env mocha */

describe('State Resource Tests', function () {
describe('Import and Synchronize State Resources', function () {
this.timeout(process.env.TIMEOUT || 5000)

@@ -33,4 +33,4 @@ const IMPORT_STATE_MACHINE_NAME = 'tymlyTest_importCsv_1_0'

it('should boot Tymly', function (done) {
tymly.boot(
it('boot Tymly', async () => {
const tymlyServices = await tymly.boot(
{

@@ -46,15 +46,12 @@ pluginPaths: [

config: {}
},
function (err, tymlyServices) {
expect(err).to.eql(null)
tymlyService = tymlyServices.tymly
client = tymlyServices.storage.client
statebox = tymlyServices.statebox
done()
}
)
tymlyService = tymlyServices.tymly
client = tymlyServices.storage.client
statebox = tymlyServices.statebox
})
it('should execute importingCsvFiles', function (done) {
statebox.startExecution(
it('execute importingCsvFiles', async () => {
const executionDescription = await statebox.startExecution(
{

@@ -66,38 +63,29 @@ sourceDir: path.resolve(__dirname, './fixtures/input')

sendResponse: 'COMPLETE'
},
function (err, executionDescription) {
expect(err).to.eql(null)
expect(executionDescription.status).to.eql('SUCCEEDED')
expect(executionDescription.currentStateName).to.equal('ImportingCsvFiles')
done()
}
)
expect(executionDescription.status).to.eql('SUCCEEDED')
expect(executionDescription.currentStateName).to.equal('ImportingCsvFiles')
})
it('should check the animals have been added', function (done) {
client.query(
'select * from tymly_test.animal_with_age',
function (err, result) {
if (err) {
done(err)
} else {
expect(result.rows[0].animal).to.eql('cat')
expect(result.rows[1].animal).to.eql('dog')
expect(result.rows[2].animal).to.eql('mouse')
it('verify the animals have been added', async () => {
const result = await client.query(
'select * from tymly_test.animal_with_age'
)
expect(result.rows[0].colour).to.eql('black')
expect(result.rows[1].colour).to.eql('brown')
expect(result.rows[2].colour).to.eql('grey')
expect(result.rows[0].animal).to.eql('cat')
expect(result.rows[1].animal).to.eql('dog')
expect(result.rows[2].animal).to.eql('mouse')
expect(result.rows[0].age).to.eql(2)
expect(result.rows[1].age).to.eql(6)
expect(result.rows[2].age).to.eql(3)
done()
}
}
)
expect(result.rows[0].colour).to.eql('black')
expect(result.rows[1].colour).to.eql('brown')
expect(result.rows[2].colour).to.eql('grey')
expect(result.rows[0].age).to.eql(2)
expect(result.rows[1].age).to.eql(6)
expect(result.rows[2].age).to.eql(3)
})
it('should execute synchronizingTable', function (done) {
statebox.startExecution(
it('execute synchronizingTable', async () => {
const executionDescription = await statebox.startExecution(
{

@@ -109,57 +97,46 @@ outputDir: OUTPUT_DIR_PATH

sendResponse: 'COMPLETE'
},
function (err, executionDescription) {
expect(err).to.eql(null)
expect(executionDescription.status).to.eql('SUCCEEDED')
expect(executionDescription.currentStateName).to.equal('SynchronizingTable')
done()
}
)
expect(executionDescription.status).to.eql('SUCCEEDED')
expect(executionDescription.currentStateName).to.equal('SynchronizingTable')
})
it('should check the animals have been added and converted', function (done) {
client.query(
'select * from tymly_test.animal_with_year',
function (err, result) {
if (err) {
done(err)
} else {
expect(result.rows.length).to.eql(3)
for (const res of result.rows) {
switch (res.animal) {
case 'dog':
expect(res.colour).to.eql('brown')
expect(res.year_born).to.eql(2011)
break
case 'cat':
expect(res.colour).to.eql('black')
expect(res.year_born).to.eql(2015)
break
case 'mouse':
expect(res.colour).to.eql('grey')
expect(res.year_born).to.eql(2014)
break
}
}
done()
}
it('verify the animals have been added and converted', async () => {
const result = await client.query(
'select * from tymly_test.animal_with_year'
)
expect(result.rows.length).to.eql(3)
for (const res of result.rows) {
switch (res.animal) {
case 'dog':
expect(res.colour).to.eql('brown')
expect(res.year_born).to.eql(2011)
break
case 'cat':
expect(res.colour).to.eql('black')
expect(res.year_born).to.eql(2015)
break
case 'mouse':
expect(res.colour).to.eql('grey')
expect(res.year_born).to.eql(2014)
break
}
)
}
})
it('should uninstall test schemas', async () => {
after('uninstall test schemas', async () => {
sqlScriptRunner.uninstall(client)
})
it('should remove output directory now tests are complete', function (done) {
after('should remove output directory now tests are complete', () => {
if (fs.existsSync(OUTPUT_DIR_PATH)) {
rimraf(OUTPUT_DIR_PATH, {}, done)
} else {
done()
rimraf.sync(OUTPUT_DIR_PATH, {})
}
})
it('should shutdown Tymly', async () => {
after('should shutdown Tymly', async () => {
await tymlyService.shutdown()
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc