Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created February 6, 2020 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/745b2dc36bd2b34b0d535fee0bf24565 to your computer and use it in GitHub Desktop.
Save jasongorman/745b2dc36bd2b34b0d535fee0bf24565 to your computer and use it in GitHub Desktop.
const assert = require('assert');
function Warehouse(catalogue) {
this.catalogue = catalogue;
this.getCd = function (artist, title) {
return this.catalogue.find((cd) => cd.artist == artist && cd.title == title);
};
this.buyCd = function (artist, title, catalogue) {
const cd = this.getCd(artist, title, catalogue);
cd.buy();
return this.catalogue;
};
}
function CD(artist, title, stock) {
this.artist = artist;
this.title = title;
this.stock = stock;
this.getStock = function () {
return this.stock;
};
this.buy = function () {
this.stock -= 1;
};
this.matches = function (artist, title) {
return this.artist == artist && this.title == title;
};
}
describe('CD Warehouse', () => {
it('reduces stock count by 1 of bought CD', () => {
const cd = new CD('Peter Gabriel', 'So', 1);
let catalogue = [
cd
];
const warehouse = new Warehouse(catalogue);
warehouse.buyCd('Peter Gabriel', 'So');
assert.equal(cd.getStock(), 0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment