mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 16:25:21 +00:00
Added tests for utils
This commit is contained in:
@@ -1,59 +1,39 @@
|
|||||||
import { splitBufferBundle } from "../lib/utils";
|
import { processDate, removeHidden } from "../lib/utils";
|
||||||
import type { BundleUnit } from "../lib/schemas";
|
|
||||||
|
|
||||||
describe("splitBufferBundle", () => {
|
describe("Utils", () => {
|
||||||
it("should split the bundle in language-organized files buffers and normal files with valid bundleUnit passed", () => {
|
describe("removeHidden", () => {
|
||||||
const zeroBuffer = Buffer.alloc(0);
|
it("should remove files that start with dot", () => {
|
||||||
const payload: BundleUnit = {
|
const filesList = [
|
||||||
"en.lproj/thumbnail@2x.png": zeroBuffer,
|
"a.png",
|
||||||
"de.lproj/background@2x.png": zeroBuffer,
|
"b.png",
|
||||||
"it.lproj/thumbnail@2x.png": zeroBuffer,
|
".DS_Store",
|
||||||
"thumbnail@2x.png": zeroBuffer,
|
"not_the_droids_you_are_looking_for.txt",
|
||||||
"background.png": zeroBuffer,
|
];
|
||||||
};
|
|
||||||
|
|
||||||
const result = splitBufferBundle(payload);
|
expect(removeHidden(filesList)).toEqual([
|
||||||
|
"a.png",
|
||||||
expect(result).toBeDefined();
|
"b.png",
|
||||||
expect(result.length).toBe(2);
|
"not_the_droids_you_are_looking_for.txt",
|
||||||
expect(result[0]).toEqual({
|
]);
|
||||||
"en.lproj": {
|
|
||||||
"thumbnail@2x.png": zeroBuffer,
|
|
||||||
},
|
|
||||||
"de.lproj": {
|
|
||||||
"background@2x.png": zeroBuffer,
|
|
||||||
},
|
|
||||||
"it.lproj": {
|
|
||||||
"thumbnail@2x.png": zeroBuffer,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(result[1]).toEqual({
|
|
||||||
"thumbnail@2x.png": zeroBuffer,
|
|
||||||
"background.png": zeroBuffer,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return empty partitionedBufferBundle if BundleUnit is empty object", () => {
|
describe("processDate", () => {
|
||||||
const result = splitBufferBundle({});
|
it("should throw Invalid date if args[0] is not a date", () => {
|
||||||
|
//@ts-expect-error
|
||||||
expect(result).toBeDefined();
|
expect(() => processDate(5)).toThrow("Invalid date");
|
||||||
expect(result.length).toBe(2);
|
//@ts-expect-error
|
||||||
expect(result[0]).toEqual({});
|
expect(() => processDate({})).toThrow("Invalid date");
|
||||||
expect(result[1]).toEqual({});
|
//@ts-expect-error
|
||||||
|
expect(() => processDate("ciao")).toThrow("Invalid date");
|
||||||
|
//@ts-expect-error
|
||||||
|
expect(() => processDate(true)).toThrow("Invalid date");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return empty partitionedBufferBundle if BundleUnit is undefined", () => {
|
it("should convert a Date object to a valid W3C date", () => {
|
||||||
const resultUndefined = splitBufferBundle(undefined);
|
expect(processDate(new Date(2020, 6, 1, 0, 0, 0, 0))).toBe(
|
||||||
const resultNull = splitBufferBundle(null);
|
"2020-07-01T00:00:00Z",
|
||||||
|
);
|
||||||
expect(resultUndefined).toBeDefined();
|
});
|
||||||
expect(resultUndefined.length).toBe(2);
|
|
||||||
expect(resultUndefined[0]).toEqual({});
|
|
||||||
expect(resultUndefined[1]).toEqual({});
|
|
||||||
|
|
||||||
expect(resultNull).toBeDefined();
|
|
||||||
expect(resultNull.length).toBe(2);
|
|
||||||
expect(resultNull[0]).toEqual({});
|
|
||||||
expect(resultNull[1]).toEqual({});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user