Skip to content

Commit

Permalink
fix(price lists): allow float values
Browse files Browse the repository at this point in the history
This commit allows float values in the Price List Items table.

Closes #1806.
  • Loading branch information
jeremielodi authored and jniles committed Aug 15, 2017
1 parent 3d1eefb commit f866d65
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
4 changes: 2 additions & 2 deletions server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ CREATE TABLE `employee` (
`date_embauche` DATETIME DEFAULT NULL,
`grade_id` BINARY(16) NOT NULL,
`nb_spouse` INT(2) DEFAULT 0,
`nb_enfant` INT(3) DEFAULT 0,
`nb_enfant` INT(3) DEFAULT 0,
`daily_salary` FLOAT DEFAULT 0,
`bank` VARCHAR(30) DEFAULT NULL,
`bank_account` VARCHAR(30) DEFAULT NULL,
Expand Down Expand Up @@ -1067,7 +1067,7 @@ CREATE TABLE `price_list_item` (
`inventory_uuid` BINARY(16) NOT NULL,
`price_list_uuid` BINARY(16) NOT NULL,
`label` VARCHAR(250) NOT NULL,
`value` INTEGER NOT NULL,
`value` DOUBLE NOT NULL,
`is_percentage` BOOLEAN NOT NULL DEFAULT 0,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`uuid`),
Expand Down
69 changes: 52 additions & 17 deletions test/integration/priceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,70 +12,86 @@ describe('(/prices ) Price List', function () {
const emptyPriceList = {
uuid : 'da4be62a-4310-4088-97a4-57c14cab49c8',
label : 'Test Empty Price List',
description : 'A price list without items attached yet.'
description : 'A price list without items attached yet.',
};

const priceListItems = [{
inventory_uuid : '289cc0a1-b90f-11e5-8c73-159fdc73ab02',
label : 'Test $11 reduction on an item',
is_percentage : false,
value : 10
value : 10,
}, {
inventory_uuid : 'c48a3c4b-c07d-4899-95af-411f7708e296',
label : 'Test 13% reduction on an item',
is_percentage : true,
value : 12
value : 12,
}];
const floatPriceListItems = [
{
inventory_uuid : '289cc0a1-b90f-11e5-8c73-159fdc73ab02',
label : 'float item value',
is_percentage : false,
value : 3.14,
},
];

const priceListItems2 = [{
inventory_uuid : '289cc0a1-b90f-11e5-8c73-159fdc73ab02',
label : 'Test $20 reduction on an item',
is_percentage : false,
value : 10
value : 10,
}, {
inventory_uuid : 'c48a3c4b-c07d-4899-95af-411f7708e296',
label : 'Test 25% reduction on an item',
is_percentage : true,
value : 12
value : 12,
}];

const priceListItemsWithDuplicates = [{
inventory_uuid : 'c48a3c4b-c07d-4899-95af-411f7708e296',
label : 'Duplicate Label',
is_percentage : false,
value : 10
value : 10,
}, {
inventory_uuid : '289cc0a1-b90f-11e5-8c73-159fdc73ab02',
label : 'Duplicate Label',
is_percentage : false,
value : 10
value : 10,
}];

const complexPriceList = {
label : 'Test Price List w/ Two Items',
description : 'A price list with two items attached.',
items : priceListItems
items : priceListItems,
};

const invalidPriceList = {
label : 'An invalid price list',
items :[{
inventory_uuid : null,
label : 'You cannot have a null inventory uuid, if you were wondering...',
is_percentage : false,
value : 1.2
}]
items :[
{
inventory_uuid : null,
label : 'You cannot have a null inventory uuid, if you were wondering...',
is_percentage : false,
value : 1.2,
},
],
};

const somePriceListWithFloatValues = {
label : 'Test Price List w/ Floats',
description : 'A price list with float values',
items : floatPriceListItems,
};

const duplicatesPriceList = {
uuid : uuid.v4(),
label : 'This list contains duplicate labels',
description : 'The list has a tone of items.',
items : priceListItemsWithDuplicates
items : priceListItemsWithDuplicates,
};

const responseKeys = [
'uuid', 'label', 'description', 'created_at', 'updated_at', 'items'
'uuid', 'label', 'description', 'created_at', 'updated_at', 'items',
];

it('GET /prices returns only one default record', function () {
Expand All @@ -86,7 +102,7 @@ describe('(/prices ) Price List', function () {
.catch(helpers.handler);
});

it('GET /prices/unknownId returns a 404 error', function () {
it('GET /prices/unknown Id returns a 404 error', function () {
return agent.get('/prices/unknownId')
.then(function (res) {
helpers.api.errored(res, 404);
Expand Down Expand Up @@ -202,6 +218,25 @@ describe('(/prices ) Price List', function () {
.catch(helpers.handler);
});


it('POST /price will register a float as a price list item', () => {
return agent.post('/prices')
.send({ list : somePriceListWithFloatValues })
.then(res => {
// assert that the records was successfully created
helpers.api.created(res);

// look up the record to make sure the price list's value is actually a float
return agent.get('/prices/'.concat(res.body.uuid));
})
.then(res => {
// ... do some checks ...
expect(res.body.items[0].value).to.equal(3.14);
})
.catch(helpers.handler);
});


it('DELETE /prices/unknownid should return a 404 error.', function () {
return agent.delete('/prices/unknownid')
.then(function (res) {
Expand Down

0 comments on commit f866d65

Please sign in to comment.