|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { handler } from "./index"; |
| 7 | +import { CDKAssetPackager } from "./asset-packager"; |
| 8 | +import { mkdir, writeFile, rm } from "node:fs/promises"; |
| 9 | +import path from "path"; |
| 10 | + |
| 11 | +const mockAssetDirectoryPath = path.join(__dirname, "mock-dir"); |
| 12 | +const mockOutputPath = path.join(__dirname, "mock-dir-output"); |
| 13 | +describe("Handler", () => { |
| 14 | + beforeAll(async function Arrange() { |
| 15 | + await rm(mockAssetDirectoryPath, { recursive: true, force: true }); |
| 16 | + await rm(mockOutputPath, { recursive: true, force: true }); |
| 17 | + await mkdir(mockAssetDirectoryPath); |
| 18 | + await mkdir(mockOutputPath); |
| 19 | + }); |
| 20 | + |
| 21 | + it("should fail in absence of path inputs ", async function () { |
| 22 | + await expect(handler("", "")).rejects.toThrowError("undefined input path"); |
| 23 | + await expect(handler(undefined, undefined)).rejects.toThrowError("undefined input path"); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should fail for invalid cdk asset path", async function () { |
| 27 | + await expect(handler("invalidPath", mockOutputPath)).rejects.toThrowError(); // TODO check error thrown |
| 28 | + }); |
| 29 | + |
| 30 | + it("should succeed if cdk assets not found", async function () { |
| 31 | + await expect(handler(mockAssetDirectoryPath, "invalidPath")).resolves; |
| 32 | + }); |
| 33 | + |
| 34 | + it("should fail for invalid output path", async function () { |
| 35 | + // Arrange |
| 36 | + const mockAssetPath = path.join(mockAssetDirectoryPath, "asset.cdkAsset.zip"); |
| 37 | + await writeFile(mockAssetPath, "NoOp"); |
| 38 | + // Act, Assert |
| 39 | + await expect(handler(mockAssetDirectoryPath, "invalidPath")).rejects.toThrowError(); // TODO check error thrown |
| 40 | + }); |
| 41 | + |
| 42 | + it("should succeed for valid paths", async function () { |
| 43 | + await expect(handler(mockAssetDirectoryPath, mockOutputPath)).resolves; |
| 44 | + // check for zip created |
| 45 | + }); |
| 46 | + |
| 47 | + afterAll(async function Cleanup() { |
| 48 | + // await rm(mockAssetDirectoryPath, { recursive: true, force: true }); |
| 49 | + // await rm(mockOutputPath, { recursive: true, force: true }); |
| 50 | + }); |
| 51 | +}); |
| 52 | + |
| 53 | +describe("CDKAssetPackager", () => { |
| 54 | + beforeAll(function Arrange() { |
| 55 | + // mock fs calls |
| 56 | + }); |
| 57 | + describe("getAssetPaths", function () { |
| 58 | + xit("should return empty array for invalid path", function () {}); |
| 59 | + xit("should return empty array when no assets found", function () {}); |
| 60 | + xit("should return array of paths when assets found", function () {}); |
| 61 | + }); |
| 62 | + describe("createAssetZip", function () { |
| 63 | + xit("should skip doing anything if path not a folder", function () {}); |
| 64 | + xit("should zip assets in the folder for valid path", function () {}); |
| 65 | + xit("should throw error if error encountered", function () {}); |
| 66 | + }); |
| 67 | + describe("moveZip", function () { |
| 68 | + xit("should move zips for valid paths", function () {}); |
| 69 | + xit("should throw error if error encountered", function () {}); |
| 70 | + }); |
| 71 | +}); |
0 commit comments