Skip to content

Commit

Permalink
Merge pull request #419 from sealink/TT-9099-convert-from-mocha-to-jest
Browse files Browse the repository at this point in the history
Tt 9099 convert from mocha to jest
  • Loading branch information
Damon1024 committed Mar 26, 2021
2 parents 9d69846 + 4b9c1db commit 761bd7e
Show file tree
Hide file tree
Showing 9 changed files with 14,138 additions and 6,974 deletions.
1 change: 1 addition & 0 deletions .github/workflows/node.yml
Expand Up @@ -13,6 +13,7 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- run: npm install -g npm@7
- run: npm ci
- run: npm run test
- run: npm run coverage
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
## Unreleased

* [TT-9025] - Expose issued_tickets board endpoint from qt
* [TT-9099] - Convert from Mocha to Jest

## 1.10.0

Expand Down
20,987 changes: 14,079 additions & 6,908 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions package.json
Expand Up @@ -10,8 +10,8 @@
"build": "rollup -c --environment BUILD:production",
"watch": "rollup -c -w",
"pretest": "rollup -c",
"test": "nyc mocha",
"coverage": "nyc report --reporter=lcov",
"test": "jest",
"coverage": "jest --coverage",
"prepublish": "BUILD=production npm test"
},
"lint-staged": {
Expand Down Expand Up @@ -45,21 +45,18 @@
"@babel/core": "^7.7.7",
"@babel/preset-env": "^7.7.7",
"babel-eslint": "^10.0.1",
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"eslint": "^7.2.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.18.0",
"istanbul": "^0.4.5",
"mocha": "^8.0.1",
"jest": "^26.6.3",
"nock": "^13.0.0",
"nyc": "^15.0.0",
"prettier": "2.2.1",
"rollup": "^2.0.2",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-istanbul": "^3.0.0",
"sinon": "^10.0.0"
"rollup-plugin-istanbul": "^3.0.0"
},
"husky": {
"hooks": {
Expand Down
13 changes: 6 additions & 7 deletions test/configApiTest.js → test/configApi.test.js
@@ -1,6 +1,5 @@
const { ConfigApi } = require("../dist/printers_qt");
const nock = require("nock");
const { expect } = require("chai");

const host = "http://127.0.0.1:8000";
const bearerToken = "bearerToken";
Expand All @@ -21,14 +20,14 @@ describe("errorHandling", () => {

it("should handle errors when listing print groups", done => {
new ConfigApi(host, bearerToken).listPrintGroupsPrinters(2).catch(err => {
expect(err.response.status).to.eq(500);
expect(err.response.status).toEqual(500);
done();
});
});

it("should handle errors when listing print groups", done => {
new ConfigApi(host, bearerToken).listPrintGroupsPrinters(2).catch(err => {
expect(err.response.status).to.eq(500);
expect(err.response.status).toEqual(500);
done();
});
});
Expand Down Expand Up @@ -56,7 +55,7 @@ describe("listPrintGroups", () => {

it("should return a hash of print groups", done => {
new ConfigApi(host, bearerToken).listPrintGroups(1).then(groups => {
expect(groups).to.have.lengthOf(2);
expect(groups).toHaveLength(2);
done();
});
});
Expand Down Expand Up @@ -93,9 +92,9 @@ describe("listPrintGroupPrinters", () => {
new ConfigApi(host, bearerToken)
.listPrintGroupsPrinters(1)
.then(printers => {
expect(printers).to.have.lengthOf(2);
expect(printers[0].description).to.eq("_DO_NOT_PRINT");
expect(printers[1].description).to.eq("PDF");
expect(printers).toHaveLength(2);
expect(printers[0].description).toEqual("_DO_NOT_PRINT");
expect(printers[1].description).toEqual("PDF");
done();
});
});
Expand Down
33 changes: 16 additions & 17 deletions test/printServiceTest.js → test/printService.test.js
@@ -1,5 +1,4 @@
const nock = require("nock");
const { expect } = require("chai");
const {
PrintService,
QUICKETS_SERVER_TYPE,
Expand Down Expand Up @@ -71,7 +70,7 @@ describe("configuration", () => {

it("should have configurable print_server_type", done => {
const printService = new PrintService(config);
expect(printService.printServerType).to.equal(QUICKETS_SERVER_TYPE);
expect(printService.printServerType).toEqual(QUICKETS_SERVER_TYPE);

const printService2 = new PrintService({
quicktravel: config.quicktravel,
Expand All @@ -81,7 +80,7 @@ describe("configuration", () => {
printServerType: ALBERT_SERVER_TYPE
}
});
expect(printService2.printServerType).to.equal(ALBERT_SERVER_TYPE);
expect(printService2.printServerType).toEqual(ALBERT_SERVER_TYPE);

done();
});
Expand Down Expand Up @@ -121,7 +120,7 @@ describe("configuration", () => {
.reply(200, { msg: "Success" });

printService.printReceipt(printGroupId, bookingId).then(response => {
expect(response).to.eq(true);
expect(response).toEqual(true);
done();
});
});
Expand Down Expand Up @@ -156,7 +155,7 @@ describe("configuration", () => {
.reply(200, { msg: "Success" });

receiptPrintService.printReceipt(printGroupId, bookingId).then(response => {
expect(response).to.eq(true);
expect(response).toEqual(true);
done();
});
});
Expand All @@ -177,7 +176,7 @@ describe("voidTickets", () => {

const printService = new PrintService(config);
printService.voidTickets(bookingId, issuedTicketIds).then(response => {
expect(response).to.deep.equal({ msg: "Success" });
expect(response).toEqual({ msg: "Success" });
done();
});
});
Expand All @@ -204,7 +203,7 @@ describe("issueTickets", () => {

const printService = new PrintService(config);
printService.issueTickets(bookingId, reservationIds).then(response => {
expect(response).to.deep.equal({ msg: "Success" });
expect(response).toEqual({ msg: "Success" });
done();
});
});
Expand All @@ -215,7 +214,7 @@ describe("issueTickets", () => {

const printService = new PrintService(config);
printService.issueTickets(bookingId, reservationIds).catch(err => {
expect(err.response.status).to.eq(500);
expect(err.response.status).toEqual(500);
done();
});
});
Expand All @@ -236,7 +235,7 @@ describe("issuedTickets", () => {
const identifier = 12345;
const printService = new PrintService(config);
printService.issuedTicket(identifier).then(response => {
expect(response).to.deep.equal({ ticket: "TICKET GOES HERE" });
expect(response).toEqual({ ticket: "TICKET GOES HERE" });
done();
});
});
Expand All @@ -251,7 +250,7 @@ describe("issuedTickets", () => {
done();
})
.catch(err => {
expect(err.response.status).to.eq(404);
expect(err.response.status).toEqual(404);
done();
});
});
Expand All @@ -276,7 +275,7 @@ describe("validate", () => {
const identifier = 123;
const printService = new PrintService(config);
printService.validateTicket(identifier).then(response => {
expect(response).to.deep.equal({ ticket: "TICKET GOES HERE" });
expect(response).toEqual({ ticket: "TICKET GOES HERE" });
done();
});
});
Expand All @@ -291,7 +290,7 @@ describe("validate", () => {
done();
})
.catch(err => {
expect(err.response.status).to.eq(422);
expect(err.response.status).toEqual(422);
done();
});
});
Expand Down Expand Up @@ -367,7 +366,7 @@ describe("reprint", () => {
printService
.reprintTickets(printGroupId, bookingId, issuedTicketIds)
.then(response => {
expect(response).to.eq(true);
expect(response).toEqual(true);
done();
});
});
Expand Down Expand Up @@ -439,7 +438,7 @@ describe("print-receipt", () => {

const printService = new PrintService(config);
printService.printReceipt(printGroupId, bookingId).then(response => {
expect(response).to.eq(true);
expect(response).toEqual(true);
done();
});
});
Expand Down Expand Up @@ -521,7 +520,7 @@ describe("printReservations", () => {
printService
.printReservations(printGroupId, bookingId, reservationIds)
.then(response => {
expect(response).to.eq(true);
expect(response).toEqual(true);
done();
});
});
Expand All @@ -535,7 +534,7 @@ describe("printReservations", () => {
printService
.printReservations(printGroupId, bookingId, reservationIds)
.then(response => {
expect(response).to.eq(false);
expect(response).toEqual(false);
done();
});
});
Expand All @@ -552,7 +551,7 @@ describe("boardTickets", () => {
it("should call wrapTickets and boardServerScans from quicktravelApi", done => {
const printService = new PrintService(config);
printService.boardTickets([{ id: '1'}]).then(response => {
expect(response).to.deep.equal([{ id: '1', status: 200, diff: [] }]);
expect(response).toEqual([{ id: '1', status: 200, diff: [] }]);
done();
});
});
Expand Down
13 changes: 6 additions & 7 deletions test/printerMatcherTest.js → test/printerMatcher.test.js
@@ -1,4 +1,3 @@
const { expect } = require("chai");
const { findPrinters } = require("../dist/printers_qt");

describe("findPrinters", () => {
Expand All @@ -16,15 +15,15 @@ describe("findPrinters", () => {
const pageFormat = { length: 200, width: 200 };
it("should return any printer without dimensions", () => {
const matches = findPrinters(printers, pageFormat);
expect(matches).to.have.lengthOf(1);
expect(matches[0].description).to.eq("TEST 1");
expect(matches).toHaveLength(1);
expect(matches[0].description).toEqual("TEST 1");
});

it("should find specific printers", () => {
const matches = findPrinters(printers, { length: 50, height: 300 });
expect(matches).to.have.lengthOf(2);
expect(matches[0].description).to.eq("TEST 1");
expect(matches[1].description).to.eq("TEST 2");
expect(matches).toHaveLength(2);
expect(matches[0].description).toEqual("TEST 1");
expect(matches[1].description).toEqual("TEST 2");
});

it("should find no matches if nothing matches", () => {
Expand All @@ -36,6 +35,6 @@ describe("findPrinters", () => {
length: 50,
height: 300
});
expect(matches).to.have.lengthOf(0);
expect(matches).toHaveLength(0);
});
});
5 changes: 2 additions & 3 deletions test/quickPrintApiTest.js → test/quickPrintApi.test.js
@@ -1,5 +1,4 @@
const nock = require("nock");
const { expect } = require("chai");
const { print, QUICKETS_SERVER_TYPE } = require("../dist/printers_qt");

const printer = {
Expand Down Expand Up @@ -32,7 +31,7 @@ describe("errors", () => {

it("should print to the printer", done => {
print(printer, pageFormat, QUICKETS_SERVER_TYPE).catch(err => {
expect(err.response.status).to.eq(500);
expect(err.response.status).toEqual(500);
done();
});
});
Expand All @@ -49,7 +48,7 @@ describe("printToPrinter", () => {

it("should print to the printer", done => {
print(printer, pageFormat, QUICKETS_SERVER_TYPE).then(response => {
expect(response).to.deep.equal({ msg: "Success" });
expect(response).toEqual({ msg: "Success" });
done();
});
});
Expand Down

0 comments on commit 761bd7e

Please sign in to comment.