Skip to content

Commit

Permalink
fix(prices): disable unique key on item labels
Browse files Browse the repository at this point in the history
This commit removes the unique key on inventory item labels.  This
causes problems when the same item is used in multiple price lists and
the user wants to give the item the same name.

Closes #1004.
  • Loading branch information
Jonathan Niles authored and sfount committed Dec 3, 2016
1 parent f2e9c29 commit faab8d7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ CREATE TABLE `price_list_item` (
`is_percentage` BOOLEAN NOT NULL DEFAULT 0,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`uuid`),
UNIQUE KEY `price_list_item_1` (`label`),
UNIQUE KEY `price_list_item_1` (`label`, `inventory_uuid`),
UNIQUE KEY `price_list_item_2` (`price_list_uuid`, `inventory_uuid`),
KEY `price_list_uuid` (`price_list_uuid`),
KEY `inventory_uuid` (`inventory_uuid`),
Expand Down
41 changes: 38 additions & 3 deletions test/integration/priceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* jshint expr : true */

const helpers = require('./helpers');
const uuid = require('node-uuid');

/*
* The /prices API endpoint
Expand All @@ -27,7 +28,6 @@ describe('(/prices ) Price List', function () {
value : 12
}];


const priceListItems2 = [{
inventory_uuid : '289cc0a1-b90f-11e5-8c73-159fdc73ab02',
label : 'Test $20 reduction on an item',
Expand All @@ -40,13 +40,25 @@ describe('(/prices ) Price List', function () {
value : 12
}];

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

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

var invalidPriceList = {
const invalidPriceList = {
label : 'An invalid price list',
items :[{
inventory_uuid : null,
Expand All @@ -56,6 +68,13 @@ describe('(/prices ) Price List', function () {
}]
};

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

const responseKeys = [
'uuid', 'label', 'description', 'created_at', 'updated_at', 'items'
];
Expand Down Expand Up @@ -168,6 +187,22 @@ describe('(/prices ) Price List', function () {
.catch(helpers.handler);
});

it('POST /prices with items with duplicate labels should be allowed.', function () {
return agent.post('/prices')
.send({ list : duplicatesPriceList })
.then(function (res) {
helpers.api.created(res);
duplicatesPriceList.uuid = res.body.uuid;
return agent.get(`/prices/${duplicatesPriceList.uuid}`);
})
.then(function (res) {
expect(res).to.have.status(200);
expect(res).to.be.json;
expect(res.body).to.have.all.keys(responseKeys);
})
.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 faab8d7

Please sign in to comment.