This repository has been archived by the owner on Jul 17, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't delete customers with packages
- Loading branch information
Showing
2 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import Customer from '../../models/customer' | |
import {createUserSession, createTestUser} from '../helpers' | ||
import User from '../../models/user' | ||
import Questionnaire from '../../models/questionnaire' | ||
import Food, {FoodItem} from '../../models/food' | ||
import Package from '../../models/package' | ||
|
||
describe('Customer Api', function() { | ||
before(async function() { | ||
|
@@ -197,6 +199,36 @@ describe('Customer Api', function() { | |
.expect(200) | ||
}) | ||
|
||
it('Won\'t delete a customer that has packages', async function () { | ||
const foodItems = [new FoodItem({ name: 'Apple', quantity: 100, startDate: '2017-06-25', frequency: 1 })] | ||
const food = await Food.create({ category: 'test', items: foodItems }) | ||
|
||
const customer = await Customer.create({ | ||
_id: 1, | ||
firstName: 'George', | ||
lastName: 'Washington', | ||
email: '[email protected]', | ||
}) | ||
|
||
await Package.create({ | ||
customer: customer._id, | ||
status: 'Packed', | ||
packedBy: 0, | ||
contents: food.items.map(item => item._id.toString()) | ||
}) | ||
|
||
const testAdmin = createTestUser('admin', ADMIN_ROLE) | ||
const session = await createUserSession(testAdmin) | ||
const request = supertest.agent(session.app) | ||
|
||
// delete the customer associated with the package | ||
return request.delete(`/api/admin/customers/${customer._id}`) | ||
.expect(409) | ||
.expect(function(res) { | ||
expect(res.body).to.have.property('message', 'This customer has packages and can\'t be deleted') | ||
}) | ||
}) | ||
|
||
it('assigns customers', async function() { | ||
const newAdmin = createTestUser('admin', ADMIN_ROLE) | ||
const newCustomer = createTestUser('customer', clientRoles.CUSTOMER) | ||
|