mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 16:25:21 +00:00
Removed repeated code in createPass and added few tests and moved few tests from index.ts to new factory test file
This commit is contained in:
97
spec/factory.ts
Normal file
97
spec/factory.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { createPass } from "../lib/factory";
|
||||
import formatMessage from "../lib/messages";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
describe("createPass", () => {
|
||||
it("should throw if first argument is not provided", async () => {
|
||||
await expectAsync(createPass(undefined)).toBeRejectedWithError(
|
||||
formatMessage("CP_NO_OPTS")
|
||||
);
|
||||
});
|
||||
|
||||
try {
|
||||
let certificatesPath = "../certificates";
|
||||
|
||||
try {
|
||||
fs.accessSync(path.resolve(__dirname, certificatesPath));
|
||||
} catch (err) {
|
||||
certificatesPath = "../certs";
|
||||
|
||||
try {
|
||||
fs.accessSync(path.resolve(__dirname, certificatesPath));
|
||||
} catch (err) {
|
||||
certificatesPath = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (certificatesPath) {
|
||||
it("should return a pass instance", async () => {
|
||||
await expectAsync(createPass({
|
||||
model: path.resolve(__dirname, "../examples/models/exampleBooking.pass"),
|
||||
certificates: {
|
||||
signerCert: path.resolve(__dirname, certificatesPath, "./signerCert.pem"),
|
||||
signerKey: {
|
||||
keyFile: path.resolve(__dirname, certificatesPath, "./signerKey.pem"),
|
||||
passphrase: "password1234"
|
||||
},
|
||||
wwdr: path.resolve(__dirname, certificatesPath, "./WWDR.pem"),
|
||||
}
|
||||
})).toBeResolved();
|
||||
});
|
||||
|
||||
describe("Model validation", () => {
|
||||
it("Should reject with non valid model", async () => {
|
||||
await expectAsync(createPass({
|
||||
// @ts-expect-error
|
||||
model: 0,
|
||||
certificates: {
|
||||
signerCert: path.resolve(__dirname, certificatesPath, "./signerCert.pem"),
|
||||
signerKey: {
|
||||
keyFile: path.resolve(__dirname, certificatesPath, "./signerKey.pem"),
|
||||
passphrase: "password1234"
|
||||
},
|
||||
wwdr: path.resolve(__dirname, certificatesPath, "./WWDR.pem"),
|
||||
}
|
||||
})).toBeRejected();
|
||||
|
||||
await expectAsync(createPass({
|
||||
model: undefined,
|
||||
certificates: {
|
||||
signerCert: path.resolve(__dirname, certificatesPath, "./signerCert.pem"),
|
||||
signerKey: {
|
||||
keyFile: path.resolve(__dirname, certificatesPath, "./signerKey.pem"),
|
||||
passphrase: "password1234"
|
||||
},
|
||||
wwdr: path.resolve(__dirname, certificatesPath, "./WWDR.pem"),
|
||||
}
|
||||
})).toBeRejected();
|
||||
|
||||
await expectAsync(createPass({
|
||||
model: null,
|
||||
certificates: {
|
||||
signerCert: path.resolve(__dirname, certificatesPath, "./signerCert.pem"),
|
||||
signerKey: {
|
||||
keyFile: path.resolve(__dirname, certificatesPath, "./signerKey.pem"),
|
||||
passphrase: "password1234"
|
||||
},
|
||||
wwdr: path.resolve(__dirname, certificatesPath, "./WWDR.pem"),
|
||||
}
|
||||
})).toBeRejected();
|
||||
|
||||
await expectAsync(createPass({
|
||||
model: {},
|
||||
certificates: {
|
||||
signerCert: path.resolve(__dirname, certificatesPath, "./signerCert.pem"),
|
||||
signerKey: {
|
||||
keyFile: path.resolve(__dirname, certificatesPath, "./signerKey.pem"),
|
||||
passphrase: "password1234"
|
||||
},
|
||||
wwdr: path.resolve(__dirname, certificatesPath, "./WWDR.pem"),
|
||||
}
|
||||
})).toBeRejected();
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (err) { }
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createPass, Pass } from "..";
|
||||
import * as path from "path";
|
||||
|
||||
/**
|
||||
* Tests created upon Jasmine testing suite.
|
||||
@@ -8,12 +9,12 @@ describe("Passkit-generator", function () {
|
||||
let pass: Pass;
|
||||
beforeEach(async () => {
|
||||
pass = await createPass({
|
||||
model: "examples/models/examplePass.pass",
|
||||
model: path.resolve(__dirname, "../examples/models/examplePass.pass"),
|
||||
certificates: {
|
||||
wwdr: "certificates/WWDR.pem",
|
||||
signerCert: "certificates/signerCert.pem",
|
||||
wwdr: path.resolve(__dirname, "../certificates/WWDR.pem"),
|
||||
signerCert: path.resolve(__dirname, "../certificates/signerCert.pem"),
|
||||
signerKey: {
|
||||
keyFile: "certificates/signerKey.pem",
|
||||
keyFile: path.resolve(__dirname, "../certificates/signerKey.pem"),
|
||||
passphrase: "123456"
|
||||
}
|
||||
},
|
||||
@@ -21,63 +22,6 @@ describe("Passkit-generator", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Model validation", () => {
|
||||
it("Should reject with non valid model", async () => {
|
||||
await expectAsync(createPass({
|
||||
// @ts-expect-error
|
||||
model: 0,
|
||||
certificates: {
|
||||
wwdr: "certificates/WWDR.pem",
|
||||
signerCert: "certificates/signerCert.pem",
|
||||
signerKey: {
|
||||
keyFile: "certificates/signerKey.pem",
|
||||
passphrase: "123456"
|
||||
}
|
||||
},
|
||||
overrides: {}
|
||||
})).toBeRejected();
|
||||
|
||||
await expectAsync(createPass({
|
||||
model: undefined,
|
||||
certificates: {
|
||||
wwdr: "certificates/WWDR.pem",
|
||||
signerCert: "certificates/signerCert.pem",
|
||||
signerKey: {
|
||||
keyFile: "certificates/signerKey.pem",
|
||||
passphrase: "123456"
|
||||
}
|
||||
},
|
||||
overrides: {}
|
||||
})).toBeRejected();
|
||||
|
||||
await expectAsync(createPass({
|
||||
model: null,
|
||||
certificates: {
|
||||
wwdr: "certificates/WWDR.pem",
|
||||
signerCert: "certificates/signerCert.pem",
|
||||
signerKey: {
|
||||
keyFile: "certificates/signerKey.pem",
|
||||
passphrase: "123456"
|
||||
}
|
||||
},
|
||||
overrides: {}
|
||||
})).toBeRejected();
|
||||
|
||||
await expectAsync(createPass({
|
||||
model: {},
|
||||
certificates: {
|
||||
wwdr: "certificates/WWDR.pem",
|
||||
signerCert: "certificates/signerCert.pem",
|
||||
signerKey: {
|
||||
keyFile: "certificates/signerKey.pem",
|
||||
passphrase: "123456"
|
||||
}
|
||||
},
|
||||
overrides: {}
|
||||
})).toBeRejected();
|
||||
});
|
||||
});
|
||||
|
||||
describe("localize()", () => {
|
||||
it("Won't apply changes without at least one parameter", () => {
|
||||
// @ts-expect-error
|
||||
|
||||
Reference in New Issue
Block a user