-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathcreate-gateway.unit.test.js
More file actions
67 lines (56 loc) · 1.94 KB
/
create-gateway.unit.test.js
File metadata and controls
67 lines (56 loc) · 1.94 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
62
63
64
65
66
67
// 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 {
CreateGatewayCommand,
IoTSiteWiseClient,
} from "@aws-sdk/client-iotsitewise";
import { main } from "../actions/create-gateway.js";
describe("createGateway", () => {
beforeEach(() => {
vi.resetAllMocks();
});
it("should create a Gateway successfully", async () => {
const mockGatewayDescription = {
gatewayArn: "0123456789ab",
gatewayId: "abcdefghijk",
};
const sendMock = vi
.spyOn(IoTSiteWiseClient.prototype, "send")
.mockResolvedValueOnce({
gatewayDescription: mockGatewayDescription,
});
const result = await main({
gatewayName: "test-name",
});
expect(sendMock).toHaveBeenCalledWith(expect.any(CreateGatewayCommand));
expect(result.gatewayDescription).toEqual(mockGatewayDescription);
});
it("should handle IoTSiteWiseError error", async () => {
const mockError = new Error("Resource not found");
mockError.name = "IoTSiteWiseError";
const sendMock = vi
.spyOn(IoTSiteWiseClient.prototype, "send")
.mockRejectedValueOnce(mockError);
const consoleWarnSpy = vi.spyOn(console, "warn");
await main({
gatewayName: "test-name",
});
expect(sendMock).toHaveBeenCalledWith(expect.any(CreateGatewayCommand));
expect(consoleWarnSpy).toHaveBeenCalledWith(
`${mockError.message}. There was a problem creating the Gateway.`,
);
});
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({
gatewayName: "test-name",
}),
).rejects.toThrow(mockError);
expect(sendMock).toHaveBeenCalledWith(expect.any(CreateGatewayCommand));
});
});