Skip to content
Permalink
Browse files
Merge pull request #12 from 340CT-1920SEPJAN/hotfix/0.2
Hotfix/0.2
  • Loading branch information
sellers3 committed Nov 27, 2019
2 parents e353e8c + fc3c7e3 commit 0ffe1eca30bade6a2f0091fef119472c6c10f758
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 51 deletions.
@@ -28,9 +28,16 @@ module.exports = class Order {
}

async addItem(data) {
const sql = `INSERT INTO items(name, price, type) VALUES("${data.itemName}", ${data.itemPrice}, "${data.itemType}")`
await this.db.run(sql)
return true
try {
if(data.itemName.length === 0) throw new Error('missing Item Name')
if(data.itemPrice.length === 0) throw new Error('missing Item Price')
if(data.itemType.length === 0) throw new Error('missing Item Type')
const sql = `INSERT INTO items(name, price, type) VALUES("${data.itemName}", ${data.itemPrice}, "${data.itemType}")`
await this.db.run(sql)
return true
} catch(err) {
throw err
}
}

async editItem(data) {
@@ -56,8 +56,17 @@ module.exports = class User {
}

async checkAuth(auth) {
if(auth !== 'Admin' || auth !== 'Kitchen' || auth !== 'Waiting') {
return true
} else false
const authentication = auth
let output = false
if(authentication === 'Admin') {
output = false
} else if(authentication === 'Kitchen') {
output = false
} else if(authentication === 'Waiting') {
output = false
} else {
output = true
}
return output
}
}

This file was deleted.

@@ -11,6 +11,30 @@ describe('addItem()', () => {
expect(addItem).toBe(true)
done()
})

test('adding an item without a name', async done => {
expect.assertions(1)
const order = await new Order()
await expect( order.addItem({itemName: '', itemPrice: 9.25, itemType: 'Main'}) )
.rejects.toEqual( Error('missing Item Name') )
done()
})

test('adding an item without a price', async done => {
expect.assertions(1)
const order = await new Order()
await expect( order.addItem({itemName: 'Chicken_Balti', itemPrice: '', itemType: 'Main'}) )
.rejects.toEqual( Error('missing Item Price') )
done()
})

test('adding an item without a type', async done => {
expect.assertions(1)
const order = await new Order()
await expect( order.addItem({itemName: 'Chicken_Balti', itemPrice: 9.25, itemType: ''}) )
.rejects.toEqual( Error('missing Item Type') )
done()
})
})

describe('getItemsID()', () => {
@@ -81,3 +81,26 @@ describe('getAuth()', () => {
})

})

describe('checkAuth()', () => {
test('checking the auth of the account', async done => {
expect.assertions(1)
const account = await new Accounts()
const noAuth = await account.checkAuth(undefined)
expect(noAuth).toBe(true)
done()
})

test('checking the auth of an invalid account', async done => {
expect.assertions(3)
const account = await new Accounts()
const admin = await account.checkAuth('Admin')
const kitchen = await account.checkAuth('Kitchen')
const waiting = await account.checkAuth('Waiting')
expect(admin).toBe(false)
expect(kitchen).toBe(false)
expect(waiting).toBe(false)
done()
})

})

0 comments on commit 0ffe1ec

Please sign in to comment.