-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwordpress-versions.test.ts
More file actions
134 lines (105 loc) · 3.64 KB
/
wordpress-versions.test.ts
File metadata and controls
134 lines (105 loc) · 3.64 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import nock from "nock";
import { expect, test } from "vitest";
import { LatestVersionError } from "../src/exceptions/LatestVersionError";
import { wordpressVersions } from "../src/wordpress-versions";
import beta from "./version-check-responses/beta.json";
import rc from "./version-check-responses/rc.json";
import stable from "./version-check-responses/stable.json";
test("wordpressVersions works correctly when only stable version is available", async () => {
expect.assertions(1);
nock("https://api.wordpress.org")
.get("/core/version-check/1.7/?channel=beta")
.reply(200, stable as Record<string, unknown>);
await expect(wordpressVersions()).resolves.toStrictEqual({
beta: null,
rc: null,
stable: "6.3",
});
});
test("wordpressVersions works correctly when both stable and beta versions are available", async () => {
expect.assertions(1);
nock("https://api.wordpress.org")
.get("/core/version-check/1.7/?channel=beta")
.reply(200, beta as Record<string, unknown>);
await expect(wordpressVersions()).resolves.toStrictEqual({
beta: "6.3",
rc: null,
stable: "6.2",
});
});
test("wordpressVersions works correctly when stable, RC, and beta versions are available", async () => {
expect.assertions(1);
nock("https://api.wordpress.org")
.get("/core/version-check/1.7/?channel=beta")
.reply(200, rc as Record<string, unknown>);
await expect(wordpressVersions()).resolves.toStrictEqual({
beta: "6.3",
rc: "6.3",
stable: "6.2",
});
});
test("wordpressVersions fails gracefully on connection issues", async () => {
expect.assertions(1);
await expect(wordpressVersions()).rejects.toThrow(LatestVersionError);
});
test("wordpressVersions fails gracefully on connection issues 2", async () => {
expect.assertions(1);
nock("https://api.wordpress.org")
.get("/core/version-check/1.7/?channel=beta")
.reply(404);
await expect(wordpressVersions()).rejects.toThrow(LatestVersionError);
});
test("wordpressVersions fails gracefully on invalid response", async () => {
expect.assertions(1);
nock("https://api.wordpress.org")
.get("/core/version-check/1.7/?channel=beta")
.reply(200);
await expect(wordpressVersions()).rejects.toThrow(LatestVersionError);
});
test("wordpressVersions fails gracefully on invalid response 2", async () => {
expect.assertions(1);
nock("https://api.wordpress.org")
.get("/core/version-check/1.7/?channel=beta")
.reply(200, {
translations: [],
});
await expect(wordpressVersions()).rejects.toThrow(LatestVersionError);
});
test("wordpressVersions fails gracefully on invalid response 3", async () => {
expect.assertions(1);
nock("https://api.wordpress.org")
.get("/core/version-check/1.7/?channel=beta")
.reply(200, {
offers: [],
translations: [],
});
await expect(wordpressVersions()).rejects.toThrow(LatestVersionError);
});
test("wordpressVersions fails gracefully on invalid response 4", async () => {
expect.assertions(1);
nock("https://api.wordpress.org")
.get("/core/version-check/1.7/?channel=beta")
.reply(200, {
offers: [
{
current: "0.42.1",
},
],
translations: [],
});
await expect(wordpressVersions()).rejects.toThrow(LatestVersionError);
});
test("wordpressVersions fails gracefully on invalid response 5", async () => {
expect.assertions(1);
nock("https://api.wordpress.org")
.get("/core/version-check/1.7/?channel=beta")
.reply(200, {
offers: [
{
response: "latest",
},
],
translations: [],
});
await expect(wordpressVersions()).rejects.toThrow(LatestVersionError);
});