-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjourney.test.ts
168 lines (150 loc) · 5.61 KB
/
journey.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import {DbVersionProvider, DbVersionSupport} from "./dbVersion";
const EMPTY_VERSION = "";
const VERSION_1 = "1.2.3";
const VERSION_2 = "2.3.4";
describe("db version provider", () => {
it("should return empty version", () => {
const versionGetter = () => Promise.resolve(EMPTY_VERSION);
const dbVersionProvider = new DbVersionProvider(versionGetter);
return dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(EMPTY_VERSION))
.catch(() => {
throw new Error("version should always resolve successfully")
});
});
it("should return proper version", () => {
const versionGetter = () => Promise.resolve(VERSION_1);
const dbVersionProvider = new DbVersionProvider(versionGetter);
return dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(VERSION_1))
.catch(() => {
throw new Error("version should always resolve successfully")
});
});
it("should return new version after refresh", async () => {
let callsCounter = 0;
const versionGetter = () => {
switch (++callsCounter) {
case 1:
return Promise.resolve(VERSION_1);
case 2:
return Promise.resolve(VERSION_2);
default:
fail("should not be called more then 2 times");
}
};
const dbVersionProvider = new DbVersionProvider(versionGetter);
await dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(VERSION_1))
.catch(() => {
throw new Error("version should always resolve successfully")
});
await dbVersionProvider.refresh(true);
await dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(VERSION_2))
.catch(() => {
throw new Error("version should always resolve successfully")
});
});
it("should fetch version once", async () => {
let callsCounter = 0;
const versionGetter = () => {
switch (++callsCounter) {
case 1:
return Promise.resolve(VERSION_1);
default:
fail("should not be called more then 1 time");
}
};
const dbVersionProvider = new DbVersionProvider(versionGetter);
await dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(VERSION_1))
.catch(() => {
throw new Error("version should always resolve successfully")
});
await dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(VERSION_1))
.catch(() => {
throw new Error("version should always resolve successfully")
});
await dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(VERSION_1))
.catch(() => {
throw new Error("version should always resolve successfully")
});
expect(callsCounter).toBe(1);
});
it("should fetch version until success", async () => {
let callsCounter = 0;
const versionGetter = () => {
switch (++callsCounter) {
case 1:
case 2:
return Promise.resolve(EMPTY_VERSION);
case 3:
return Promise.resolve(VERSION_1);
default:
fail("should not be called more then 3 times");
}
};
const dbVersionProvider = new DbVersionProvider(versionGetter);
await dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(EMPTY_VERSION))
.catch(() => {
throw new Error("version should always resolve successfully")
});
await dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(EMPTY_VERSION))
.catch(() => {
throw new Error("version should always resolve successfully")
});
await dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(VERSION_1))
.catch(() => {
throw new Error("version should always resolve successfully")
});
await dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(VERSION_1))
.catch(() => {
throw new Error("version should always resolve successfully")
});
await dbVersionProvider.getVersionPromise()
.then(version => expect(version).toBe(VERSION_1))
.catch(() => {
throw new Error("version should always resolve successfully")
});
expect(callsCounter).toBe(3);
});
});
describe("db version support", () => {
it("should not support", () => {
const notSupportedVersions = ["0.11", "1.13.9", "1.13", "1.0"];
notSupportedVersions.forEach(async version => {
const dbVersionProvider = new DbVersionProvider(() => Promise.resolve(version))
const dbVersionSupport = new DbVersionSupport(dbVersionProvider);
await dbVersionSupport.supportsClassNameNamespacedEndpointsPromise()
.then(support => {
expect(support.supports).toBe(false);
expect(support.version).toBe(version);
})
.catch(() => {
throw new Error("version should always resolve successfully")
});
});
});
it("should support", () => {
const supportedVersions = ["1.14.0", "1.14.9", "1.100", "2.0", "10.11.12"];
supportedVersions.forEach(async version => {
const dbVersionProvider = new DbVersionProvider(() => Promise.resolve(version))
const dbVersionSupport = new DbVersionSupport(dbVersionProvider);
await dbVersionSupport.supportsClassNameNamespacedEndpointsPromise()
.then(support => {
expect(support.supports).toBe(true);
expect(support.version).toBe(version);
})
.catch(() => {
throw new Error("version should always resolve successfully")
});
});
});
});