-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathdelete-gateway.unit.test.js
More file actions
61 lines (50 loc) · 1.78 KB
/
delete-gateway.unit.test.js
File metadata and controls
61 lines (50 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { describe, it, expect, vi, beforeEach } from "vitest";
import {
DeleteGatewayCommand,
IoTSiteWiseClient,
} from "@aws-sdk/client-iotsitewise";
import { main } from "../actions/delete-gateway.js";
describe("deleteGateway", () => {
beforeEach(() => {
vi.resetAllMocks();
});
it("should delete a Gateway successfully", async () => {
const sendMock = vi
.spyOn(IoTSiteWiseClient.prototype, "send")
.mockResolvedValueOnce({});
const result = await main({
gatewayId: "1234567890ab",
});
expect(sendMock).toHaveBeenCalledWith(expect.any(DeleteGatewayCommand));
expect(result.gatewayDeleted).toEqual(true);
});
it("should handle ResourceNotFound error", async () => {
const mockError = new Error("Resource not found");
mockError.name = "ResourceNotFound";
const sendMock = vi
.spyOn(IoTSiteWiseClient.prototype, "send")
.mockRejectedValueOnce(mockError);
const consoleWarnSpy = vi.spyOn(console, "warn");
await main({
gatewayId: "1234567890ab",
});
expect(sendMock).toHaveBeenCalledWith(expect.any(DeleteGatewayCommand));
expect(consoleWarnSpy).toHaveBeenCalledWith(
`${mockError.message}. The Gateway could not be found. Please check the Gateway Id.`,
);
});
it("should throw any other errors", async () => {
const mockError = new Error("Something went wrong");
const sendMock = vi
.spyOn(IoTSiteWiseClient.prototype, "send")
.mockRejectedValueOnce(mockError);
await expect(
main({
gatewayId: "1234567890ab",
}),
).rejects.toThrow(mockError);
expect(sendMock).toHaveBeenCalledWith(expect.any(DeleteGatewayCommand));
});
});