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