This repository was archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherrors.test.ts
80 lines (67 loc) · 2.15 KB
/
errors.test.ts
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
68
69
70
71
72
73
74
75
76
77
78
79
80
import test from "ava"
import { v4 as uuidv4, validate as validateUUID } from "uuid"
import Seam, { SeamAPIError, SeamMalformedInputError } from "../src"
import { getServer } from "./fixtures/plugins/get-server-plugin"
test("should throw instances of SeamAPIError", async (t) => {
const { client } = await getServer()
try {
await client.devices.get({ device_id: uuidv4() })
t.fail()
} catch (error) {
t.is(error instanceof SeamAPIError, true)
t.is((error as SeamAPIError).status, 404)
t.like((error as SeamAPIError).metadata, {
type: "device_not_found",
message: "device not found",
})
}
})
test("error has request ID", async (t) => {
const { client } = await getServer()
try {
await client.devices.get({ device_id: uuidv4() })
t.fail()
} catch (error) {
t.is(error instanceof SeamAPIError, true)
t.true(validateUUID((error as SeamAPIError).requestId))
}
})
test("should throw on malformed input with details", async (t) => {
const { client } = await getServer()
try {
await client.devices.get({ device_id: "invalid-device-id" })
t.fail()
} catch (error) {
t.is(error instanceof SeamMalformedInputError, true)
t.snapshot((error as SeamMalformedInputError).validationErrors)
t.snapshot((error as SeamMalformedInputError).toString())
}
})
test("waiting on an errored action attempt should throw", async (t) => {
const { client, seed } = await getServer(true)
const ACCESS_CODE_TO_DUPLICATE = "111111"
await client.accessCodes.create({
device_id: seed.devices.augustLock.id1,
code: ACCESS_CODE_TO_DUPLICATE,
})
await t.throwsAsync(
() =>
client.accessCodes.create({
device_id: seed.devices.augustLock.id1,
code: ACCESS_CODE_TO_DUPLICATE,
}),
{
instanceOf: SeamAPIError,
}
)
})
test("constructor throws if empty API key passed", (t) => {
t.throws(() => new Seam(""))
t.notThrows(() => new Seam("some-api-key"))
})
test("constructor throws if no API key is present in env", (t) => {
process.env.SEAM_API_KEY = ""
t.throws(() => new Seam())
process.env.SEAM_API_KEY = "some-api-key"
t.notThrows(() => new Seam())
})