Commit 7a39de62 authored by aguestuser's avatar aguestuser

Merge branch 'hotfix-repair-phoneNumber-destroy' into 'main'

[hotfix] whoops! introduced bug that broke destroy

See merge request !388
parents 6090a036 c4fcec56
......@@ -14,7 +14,7 @@ const create = ({ phoneNumber, twilioSid, status }) =>
const destroy = async (phoneNumber, transaction) => {
const phoneNumberRecord = await find(phoneNumber)
return phoneNumberRecord
? phoneNumber.destroy({ ...(transaction ? { transaction } : {}) }).then(() => true)
? phoneNumberRecord.destroy({ ...(transaction ? { transaction } : {}) }).then(() => true)
: false
}
......
......@@ -16,7 +16,7 @@ describe('phone number repository', () => {
before(async () => {
db = (await app.run({ ...testApp, db: dbService })).db
})
afterEach(async () => await db.phoneNumber.destroy({ where: {} }))
afterEach(async () => await db.phoneNumber.destroy({ where: {}, force: true }))
after(async () => await app.stop())
describe('#create', () => {
......@@ -82,4 +82,29 @@ describe('phone number repository', () => {
})
})
})
describe('#destroy', () => {
const phoneNumber = genPhoneNumber()
let phoneNumberCount
describe('when given an existing phone number', () => {
beforeEach(async () => {
await db.phoneNumber.create(phoneNumberFactory({ phoneNumber }))
})
it('deletes the phone number', async () => {
phoneNumberCount = await db.phoneNumber.count()
expect(await phoneNumberRepository.destroy(phoneNumber)).to.eql(true)
expect(await db.phoneNumber.count()).to.eql(phoneNumberCount - 1)
})
})
describe('when given the phone number for a non-existent phoneNumber', () => {
it('does nothing', async () => {
phoneNumberCount = await db.phoneNumber.count()
expect(await phoneNumberRepository.destroy(genPhoneNumber())).to.eql(false)
expect(await db.phoneNumber.count()).to.eql(phoneNumberCount)
})
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment