mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
adds golden master test
This commit is contained in:
parent
99906235bd
commit
fd35bf5be1
0
TypeScript/build/.gitkeep
Normal file
0
TypeScript/build/.gitkeep
Normal file
@ -6,7 +6,9 @@
|
||||
"precompile": "rimraf app/**/*.js test/**/*.js",
|
||||
"compile": "tsc",
|
||||
"pretest": "rimraf app/**/*.js test/**/*.js",
|
||||
"test": "nyc mocha"
|
||||
"test": "nyc mocha",
|
||||
"test:gm": "nyc mocha -g 'gilded rose golden master'",
|
||||
"create-master": "ts-node ./test/generateGoldenMaster.ts"
|
||||
},
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
@ -19,7 +21,7 @@
|
||||
"nyc": "~15.1.0",
|
||||
"rimraf": "~3.0.2",
|
||||
"source-map-support": "0.5.19",
|
||||
"ts-node": "~9.1.1",
|
||||
"ts-node": "^10.2.1",
|
||||
"typescript": "~4.1.3"
|
||||
},
|
||||
"nyc": {
|
||||
|
||||
26
TypeScript/test/checkGoldenMaster.spec.ts
Normal file
26
TypeScript/test/checkGoldenMaster.spec.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import * as fs from "fs";
|
||||
import {generateReport, getItems, goldenMasterFilename} from "./generateReport";
|
||||
import {GildedRose} from "../app/gilded-rose";
|
||||
import { expect } from "chai";
|
||||
|
||||
function getGoldenMaster() {
|
||||
try {
|
||||
return fs.readFileSync(goldenMasterFilename).toString().split('\n')
|
||||
}catch {
|
||||
throw new Error('No golden master file generated; run `yarn create-master` or `npm run create-master`')
|
||||
}
|
||||
}
|
||||
|
||||
describe('gilded rose golden master', () => {
|
||||
it('should match golden master', () => {
|
||||
const goldenMaster = getGoldenMaster();
|
||||
|
||||
const newReport = generateReport(new GildedRose(getItems()))
|
||||
|
||||
expect(newReport.length).to.equal(goldenMaster.length)
|
||||
|
||||
goldenMaster.forEach((line, index) => {
|
||||
expect(newReport[index]).to.equal(line)
|
||||
})
|
||||
})
|
||||
})
|
||||
7
TypeScript/test/generateGoldenMaster.ts
Normal file
7
TypeScript/test/generateGoldenMaster.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import * as fs from "fs";
|
||||
import {generateReport, getItems, goldenMasterFilename} from "./generateReport";
|
||||
import {GildedRose} from "../app/gilded-rose";
|
||||
|
||||
|
||||
const report = generateReport(new GildedRose(getItems()))
|
||||
fs.writeFileSync(goldenMasterFilename, report.join('\n'))
|
||||
34
TypeScript/test/generateReport.ts
Normal file
34
TypeScript/test/generateReport.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import {GildedRose, Item} from "../app/gilded-rose";
|
||||
|
||||
export const goldenMasterFilename = './build/goldenMaster.txt';
|
||||
|
||||
export const getItems = () => ([
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6)
|
||||
]);
|
||||
|
||||
export function generateReport(gildedRose: GildedRose) {
|
||||
const outputLines: string[] = []
|
||||
|
||||
const days: number = 2;
|
||||
|
||||
for (let i = 0; i < days; i++) {
|
||||
outputLines.push("-------- day " + i + " --------");
|
||||
outputLines.push("name, sellIn, quality");
|
||||
gildedRose.items.forEach(element => {
|
||||
outputLines.push(element.name + ' ' + element.sellIn + ' ' + element.quality);
|
||||
});
|
||||
outputLines.push();
|
||||
gildedRose.updateQuality();
|
||||
}
|
||||
|
||||
return outputLines
|
||||
}
|
||||
@ -3,10 +3,10 @@ import { Item, GildedRose } from '../app/gilded-rose';
|
||||
|
||||
describe('Gilded Rose', function () {
|
||||
|
||||
it('should foo', function() {
|
||||
const gildedRose = new GildedRose([ new Item('foo', 0, 0) ]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).to.equal('fixme');
|
||||
});
|
||||
// it('should foo', function() {
|
||||
// const gildedRose = new GildedRose([ new Item('foo', 0, 0) ]);
|
||||
// const items = gildedRose.updateQuality();
|
||||
// expect(items[0].name).to.equal('fixme');
|
||||
// });
|
||||
|
||||
});
|
||||
|
||||
@ -1,27 +1,5 @@
|
||||
import { Item, GildedRose } from '../app/gilded-rose';
|
||||
import {generateReport, getItems} from "./generateReport";
|
||||
import {GildedRose} from "../app/gilded-rose";
|
||||
|
||||
const items = [
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6)];
|
||||
|
||||
|
||||
const gildedRose = new GildedRose(items);
|
||||
var days: number = 2;
|
||||
for (let i = 0; i < days; i++) {
|
||||
console.log("-------- day " + i + " --------");
|
||||
console.log("name, sellIn, quality");
|
||||
items.forEach(element => {
|
||||
console.log(element.name + ' ' + element.sellIn + ' ' + element.quality);
|
||||
|
||||
});
|
||||
console.log();
|
||||
gildedRose.updateQuality();
|
||||
}
|
||||
const outputLines = generateReport(new GildedRose(getItems()));
|
||||
console.log(outputLines.join('\n'))
|
||||
Loading…
Reference in New Issue
Block a user