-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
57 lines (50 loc) · 1.43 KB
/
index.test.js
File metadata and controls
57 lines (50 loc) · 1.43 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
import { unstable_dev } from 'wrangler';
import { describe, expect, it, beforeAll, afterAll } from 'vitest';
describe('Worker', () => {
let worker;
beforeAll(async () => {
worker = await unstable_dev('index.js', {}, { disableExperimentalWarning: true });
});
afterAll(async () => {
await worker.stop();
});
it('Should retun a simple message', async () => {
const resp = await worker.fetch('/');
if (resp) {
const text = await resp.text();
expect(text).toMatchInlineSnapshot(
`"App is live!"`
);
}
});
it('should return status 400', async () => {
const resp = await worker.fetch('/webhook', {
method: "POST",
body: "{}"
});
if (resp) {
const text = await resp.text();
expect(text).toBe('Invalid body');
expect(resp.status).toBe(400);
}
});
it('should return 401 reponse', async () => {
const resp = await worker.fetch('/webhook', {
body: JSON.stringify({ botId: "botId", voterId: "voterId", provider: "wrangler-tests", date: "2024-03-24T08:58:00.755Z" }),
method: 'POST',
});
if (resp) {
const txt = await resp.text();
expect(txt).toBe("Unauthorized");
expect(resp.status).toBe(401);
}
});
it('should return 404 for undefined routes', async () => {
const resp = await worker.fetch('/foobar');
if (resp) {
const txt = await resp.text()
expect(txt).toBe("Not found")
expect(resp.status).toBe(404);
}
});
});