Verified Commit c4fcec56 authored by aguestuser's avatar aguestuser

[hotfix] whoops! introduced bug that broke destroy

* phoneNubmerRepository.destroy called `phoneNumber.destroy` instead
  of `phoneNumberRecord.destroy`
* this fixes it and adds a unit test
parent 6090a036
Pipeline #45959 passed with stage
in 2 minutes and 28 seconds
......@@ -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