Skip to content

Commit

Permalink
Fixed tests for running with mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
danjoa committed Dec 22, 2023
1 parent ae8bd32 commit 93e490b
Showing 1 changed file with 59 additions and 60 deletions.
119 changes: 59 additions & 60 deletions test/drafts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ axios.defaults.auth = { username: 'alice' }
describe('Draft Choreography APIs', () => {
let draftId, incidentId

it('Create an incident ', async () => {
it('Create a new incident', async () => {
const { status, statusText, data } = await POST(`/odata/v4/processor/Incidents`, {
title: 'Urgent attention required !',
status_code: 'N'
Expand All @@ -16,15 +16,15 @@ describe('Draft Choreography APIs', () => {
expect(statusText).to.equal('Created')
})

it('+ Activate the draft & check Urgency code as H using custom logic', async () => {
it('Save the draft & check urgency code as H using custom logic', async () => {
const response = await POST(
`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=false)/ProcessorService.draftActivate`
)
expect(response.status).to.eql(201)
expect(response.data.urgency_code).to.eql('H')
})

it('+ Test the incident status', async () => {
it ('should test the incident status', async () => {
const {
status,
data: { status_code, ID }
Expand All @@ -34,74 +34,73 @@ describe('Draft Choreography APIs', () => {
expect(status_code).to.eql('N')
})

describe('Close Incident and Open it again to check Custom logic', () => {
it(`Should Close the Incident-${draftId}`, async () => {
const { status } = await POST(
`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)/ProcessorService.draftEdit`,
{
PreserveChanges: true
}
)
expect(status).to.equal(201)
})
it ('should edit the incident again', async () => {
const { status } = await POST(
`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)/ProcessorService.draftEdit`,
{
PreserveChanges: true
}
)
expect(status).to.equal(201)
})

it(`Should Close the Incident-${draftId}`, async () => {
const { status } = await PATCH(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)`, {
status_code: 'C'
})
expect(status).to.equal(200)
})
it('+ Activate the draft & check Status code as C using custom logic', async () => {
const response = await POST(
`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)/ProcessorService.draftActivate`
)
expect(response.status).to.eql(200)
it (`should set status to closed`, async () => {
const { status } = await PATCH(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)`, {
status_code: 'C'
})
expect(status).to.equal(200)
})

it('+ Test the incident status to be closed', async () => {
const {
status,
data: { status_code }
} = await GET(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)`)
expect(status).to.eql(200)
expect(status_code).to.eql('C')
})
describe('should fail to re-open closed incident', () => {
it(`Should Open Closed Incident-${draftId}`, async () => {
const { status } = await POST(
`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)/ProcessorService.draftEdit`,
{
PreserveChanges: true
}
)
expect(status).to.equal(201)
})
it ('should save the draft & check status code as C using custom logic', async () => {
const response = await POST(
`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)/ProcessorService.draftActivate`
)
expect(response.status).to.eql(200)
})

it(`Should re-open the Incident-${draftId} but fail`, async () => {
const { status } = await PATCH(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)`, {
status_code: 'N'
})
expect(status).to.equal(200)
})
it('Should fail to activate draft trying to re-open the incident', async () => {
try {
await POST(
`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)/ProcessorService.draftActivate`
)
} catch (error) {
expect(error.response.status).to.eql(500)
expect(error.response.data.error.message).to.include(`Can't modify a closed incident`)
}
})
it ('should test the incident status to be closed', async () => {
const {
status,
data: { status_code }
} = await GET(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)`)
expect(status).to.eql(200)
expect(status_code).to.eql('C')
})

it (`should re-open the closed incident-${draftId}`, async () => {
const { status } = await POST(
`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)/ProcessorService.draftEdit`,
{
PreserveChanges: true
}
)
expect(status).to.equal(201)
})

it (`should fail setting the status to 'N'`, async () => {
const { status } = await PATCH(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)`, {
status_code: 'N'
})
expect(status).to.equal(200)
})

it ('should fail to save drafts for closed incidents', async () => {
try {
await POST(
`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)/ProcessorService.draftActivate`
)
} catch (error) {
expect(error.response.status).to.eql(500)
expect(error.response.data.error.message).to.include(`Can't modify a closed incident`)
}
})

it('- Delete the Draft', async () => {
it ('should delete the Draft', async () => {
const response = await DELETE(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=false)`)
expect(response.status).to.eql(204)
})

it('- Delete the Incident', async () => {
it ('should delete the Incident', async () => {
const response = await DELETE(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)`)
expect(response.status).to.eql(204)
})
Expand Down

0 comments on commit 93e490b

Please sign in to comment.