-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathnotes.spec.ts
More file actions
100 lines (79 loc) · 3.03 KB
/
Copy pathnotes.spec.ts
File metadata and controls
100 lines (79 loc) · 3.03 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import * as chai from "chai";
import nock from "../test/helpers/nock";
import * as chaiAsPromised from "chai-as-promised";
import { createNote, deleteNote, listNotes } from "./notes";
import { FirebaseError } from "../error";
import { crashlyticsApiOrigin } from "../api";
chai.use(chaiAsPromised);
const expect = chai.expect;
describe("notes", () => {
const appId = "1:1234567890:android:abcdef1234567890";
const requestProjectNumber = "1234567890";
const issueId = "test-issue-id";
const noteId = "test-note-id";
const noteBody = "This is a test note.";
afterEach(() => {
nock.cleanAll();
});
describe("createNote", () => {
it("should resolve with the response body on success", async () => {
const mockResponse = { name: `notes/${noteId}`, body: noteBody };
nock(crashlyticsApiOrigin())
.post(`/v1alpha/projects/${requestProjectNumber}/apps/${appId}/issues/${issueId}/notes`, {
body: noteBody,
})
.reply(200, mockResponse);
const result = await createNote(appId, issueId, noteBody);
expect(result).to.deep.equal(mockResponse);
expect(nock.isDone()).to.be.true;
});
it("should throw a FirebaseError if the appId is invalid", async () => {
const invalidAppId = "invalid-app-id";
await expect(createNote(invalidAppId, issueId, noteBody)).to.be.rejectedWith(
FirebaseError,
"Unable to get the projectId from the AppId.",
);
});
});
describe("deleteNote", () => {
it("should resolve on success", async () => {
nock(crashlyticsApiOrigin())
.delete(
`/v1alpha/projects/${requestProjectNumber}/apps/${appId}/issues/${issueId}/notes/${noteId}`,
)
.reply(200, {});
await deleteNote(appId, issueId, noteId);
expect(nock.isDone()).to.be.true;
});
it("should throw a FirebaseError if the appId is invalid", async () => {
const invalidAppId = "invalid-app-id";
await expect(deleteNote(invalidAppId, issueId, noteId)).to.be.rejectedWith(
FirebaseError,
"Unable to get the projectId from the AppId.",
);
});
});
describe("listNotes", () => {
it("should resolve with the response body on success", async () => {
const mockResponse = { notes: [{ name: "note1", body: "a note" }] };
const pageSize = 10;
nock(crashlyticsApiOrigin())
.get(`/v1alpha/projects/${requestProjectNumber}/apps/${appId}/issues/${issueId}/notes`)
.query({
page_size: `${pageSize}`,
})
.reply(200, mockResponse);
const result = await listNotes(appId, issueId, pageSize);
expect(result).to.deep.equal(mockResponse.notes);
expect(nock.isDone()).to.be.true;
});
it("should throw a FirebaseError if the appId is invalid", async () => {
const invalidAppId = "invalid-app-id";
const pageSize = 10;
await expect(listNotes(invalidAppId, issueId, pageSize)).to.be.rejectedWith(
FirebaseError,
"Unable to get the projectId from the AppId.",
);
});
});
});