Skip to content

Commit

Permalink
test: simplify tests to get times
Browse files Browse the repository at this point in the history
  • Loading branch information
meenahoda committed Oct 10, 2018
1 parent 9983e3d commit ff61901
Showing 1 changed file with 24 additions and 263 deletions.
287 changes: 24 additions & 263 deletions test/get-available-times-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,233 +6,33 @@ const expect = require('chai').expect

const GET_TIMES_STATE_MACHINE_NAME = 'test_getAvailableTimes'

const DATE_TIME_1 = '2018-04-23'
const DATE_TIME_2 = '2018-04-24'
const DATE_TIME = '2018-04-23'

// booked: 8:30-9:30, 9:30-10:30, 12:30-13:30(x5), 13:30-14:30(x5) 14:30-15:30
const initialData = [
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T08:30:00',
endDateTime: '2018-04-23T09:30:00',
info: {},
id: '6d7fdfe8-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T09:30:00',
endDateTime: '2018-04-23T10:30:00',
info: {},
id: '6d7fdb4c-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T14:30:00',
endDateTime: '2018-04-23T15:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T12:30:00',
endDateTime: '2018-04-23T13:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T12:30:00',
endDateTime: '2018-04-23T13:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T12:30:00',
endDateTime: '2018-04-23T13:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T12:30:00',
endDateTime: '2018-04-23T13:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T12:30:00',
endDateTime: '2018-04-23T13:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T13:30:00',
endDateTime: '2018-04-23T14:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T13:30:00',
endDateTime: '2018-04-23T14:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T13:30:00',
endDateTime: '2018-04-23T14:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T13:30:00',
endDateTime: '2018-04-23T14:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T13:30:00',
endDateTime: '2018-04-23T14:30:00',
info: {},
id: '6d7fde94-46d3-11e8-842f-0ed5f89f718b'
}
]
// book 3 at 10:30-11:30
// get times - should NOT see 10:30-11:30
// get times - should NOT see 12:00-13:30

// booked: 8:30-9:30(x10)
const standardMaxConcurrency = [
const data = [
{
originId: 'test',
origin: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-24T08:30:00',
endDateTime: '2018-04-24T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
startDateTime: `${DATE_TIME}T10:30:00`,
endDateTime: `${DATE_TIME}T11:30:00`,
info: {}
},
{
originId: 'test',
origin: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-24T08:30:00',
endDateTime: '2018-04-24T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
startDateTime: `${DATE_TIME}T10:30:00`,
endDateTime: `${DATE_TIME}T11:30:00`,
info: {}
},
{
originId: 'test',
origin: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-24T08:30:00',
endDateTime: '2018-04-24T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-24T08:30:00',
endDateTime: '2018-04-24T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-24T08:30:00',
endDateTime: '2018-04-24T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-24T08:30:00',
endDateTime: '2018-04-24T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-24T08:30:00',
endDateTime: '2018-04-24T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-24T08:30:00',
endDateTime: '2018-04-24T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-24T08:30:00',
endDateTime: '2018-04-24T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-24T08:30:00',
endDateTime: '2018-04-24T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
}
]

const additionalData = [
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T08:30:00',
endDateTime: '2018-04-23T09:30:00',
info: {},
id: '426b87a8-46f1-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T08:30:00',
endDateTime: '2018-04-23T09:30:00',
info: {},
id: 'b0250512-46f6-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T10:30:00',
endDateTime: '2018-04-23T11:30:00',
info: {},
id: '426b8be0-46f1-11e8-842f-0ed5f89f718b'
},
{
originId: 'test',
diaryId: 'doctors',
startDateTime: '2018-04-23T20:30:00',
endDateTime: '2018-04-23T21:30:00',
info: {},
id: '426b8e06-46f1-11e8-842f-0ed5f89f718b'
startDateTime: `${DATE_TIME}T10:30:00`,
endDateTime: `${DATE_TIME}T11:30:00`,
info: {}
}
]

Expand Down Expand Up @@ -274,68 +74,29 @@ describe('Test the get available times state resource', function () {
expect(Object.keys(diaryService.diaries).includes('test_doctors')).to.eql(true)
})

it('should setup some data in the entries model, including 5 bookings at 12:30 and 13:30 to test concurrency', async () => {
for (const datum of initialData) {
const doc = await entryModel.upsert(datum, {})
expect(doc).to.not.eql(undefined)
}
})

it('should setup some data in the entries model, to test for the general max concurrency', async () => {
for (const datum of standardMaxConcurrency) {
it('should set up some data in the entries model', async () => {
for (const datum of data) {
const doc = await entryModel.upsert(datum, {})
expect(doc).to.not.eql(undefined)
}
})

it('should find that 0830-0930 does not appear as per max standard concurrency rules', async () => {
it('should start the state machine to get available times', async () => {
const executionDescription = await statebox.startExecution(
{ date: DATE_TIME_2 },
{ date: DATE_TIME },
GET_TIMES_STATE_MACHINE_NAME,
{ sendResponse: 'COMPLETE' }
)

expect(executionDescription.currentStateName).to.eql('GetAvailableTimes')
expect(executionDescription.currentResource).to.eql('module:getAvailableDiarySlots')
expect(executionDescription.status).to.eql('SUCCEEDED')
const filtered = executionDescription.ctx.availableTimes.filter(e => e.label === '08:30 - 09:30')
expect(filtered.length).to.eql(0)
})

it('should find that 1230-1330 and 1330-1430 are not listed as available', async () => {
const executionDescription = await statebox.startExecution(
{ date: DATE_TIME_1 },
GET_TIMES_STATE_MACHINE_NAME,
{ sendResponse: 'COMPLETE' }
)

expect(executionDescription.currentStateName).to.eql('GetAvailableTimes')
expect(executionDescription.currentResource).to.eql('module:getAvailableDiarySlots')
expect(executionDescription.status).to.eql('SUCCEEDED')
expect(executionDescription.ctx.availableTimes[0].label).to.eql('08:30 - 09:30')
const filtered = executionDescription.ctx.availableTimes.filter(e => ['12:30 - 13:30', '13:30 - 14:30'].includes(e.label))
const filtered = executionDescription.ctx.availableTimes.filter(e => e.label === '10:30 - 11:30')
expect(filtered.length).to.eql(0)
})

it('should setup some test additionalData in the entries model to remove/change the availableTimes return', async () => {
for (const datum of additionalData) {
const doc = await entryModel.upsert(datum, {})
expect(doc).to.not.eql(undefined)
}
})

it('should start a second get available times state machine', async () => {
const executionDescription = await statebox.startExecution(
{ date: DATE_TIME_1 },
GET_TIMES_STATE_MACHINE_NAME,
{ sendResponse: 'COMPLETE' }
)
expect(executionDescription.currentStateName).to.eql('GetAvailableTimes')
expect(executionDescription.currentResource).to.eql('module:getAvailableDiarySlots')
expect(executionDescription.status).to.eql('SUCCEEDED')
expect(executionDescription.ctx.availableTimes[0].label).to.be.a('string')
expect(executionDescription.ctx.availableTimes[0].label).to.eql('09:30 - 10:30')
expect(executionDescription.ctx.availableTimes[0].value.includes('2018-04-23T09:30:00')).to.eql(true)
expect(executionDescription.ctx.availableTimes[0].label).to.eql('08:30 - 09:30')
expect(executionDescription.ctx.availableTimes[12].label).to.eql('21:30 - 22:30')
})

it('should shutdown Tymly', async () => {
Expand Down

0 comments on commit ff61901

Please sign in to comment.