Skip to content

Commit db28400

Browse files
committed
use more test helpers
- generateVerifyToken - tempVIP - tokenUtils
1 parent ecbf809 commit db28400

File tree

3 files changed

+165
-224
lines changed

3 files changed

+165
-224
lines changed

test/cases/generateVerifyToken.ts

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,24 @@ describe("generateToken test", function() {
6363
}).catch(err => done(err));
6464
});
6565

66-
it("Should be able to create new local token", function (done) {
66+
it("Should be able to create new local token", () =>
6767
createAndSaveToken(TokenType.local).then((licenseKey) => {
6868
assert.ok(validateLicenseKeyRegex(licenseKey[0]));
6969
localLicense = licenseKey[0];
70-
done();
71-
}).catch(err => done(err));
72-
});
70+
})
71+
);
7372

74-
it("Should return 400 if missing code parameter", function (done) {
73+
it("Should return 400 if missing code parameter", () =>
7574
getGenerateToken("patreon", null, "").then(res => {
7675
assert.strictEqual(res.status, 400);
77-
done();
78-
}).catch(err => done(err));
79-
});
76+
})
77+
);
8078

81-
it("Should return 403 if missing adminuserID parameter", function (done) {
79+
it("Should return 403 if missing adminuserID parameter", () =>
8280
getGenerateToken("local", "fake-code", null).then(res => {
8381
assert.strictEqual(res.status, 403);
84-
done();
85-
}).catch(err => done(err));
86-
});
82+
})
83+
);
8784

8885
it("Should return 403 for invalid adminuserID parameter", function (done) {
8986
getGenerateToken("local", "fake-code", "fakeAdminID").then(res => {
@@ -94,20 +91,18 @@ describe("generateToken test", function() {
9491
});
9592

9693
describe("verifyToken static tests", function() {
97-
it("Should fast reject invalid token", function (done) {
94+
it("Should fast reject invalid token", () =>
9895
getVerifyToken("00000").then(res => {
9996
assert.strictEqual(res.status, 200);
10097
assert.ok(!res.data.allowed);
101-
done();
102-
}).catch(err => done(err));
103-
});
104-
105-
it("Should return 400 if missing code token", function (done) {
106-
getVerifyToken(null).then(res => {
107-
assert.strictEqual(res.status, 400);
108-
done();
109-
}).catch(err => done(err));
110-
});
98+
})
99+
);
100+
101+
it("Should return 400 if missing code token", () =>
102+
getVerifyToken(null).then(res =>
103+
assert.strictEqual(res.status, 400)
104+
)
105+
);
111106
});
112107

113108
describe("verifyToken mock tests", function() {
@@ -121,69 +116,62 @@ describe("verifyToken mock tests", function() {
121116
mock.restore();
122117
});
123118

124-
it("Should accept current patron", function (done) {
119+
it("Should accept current patron", function () {
125120
if (!config?.patreon) this.skip();
126121
mock.onGet(/identity/).reply(200, patreon.activeIdentity);
127-
getVerifyToken(patreonLicense).then(res => {
122+
return getVerifyToken(patreonLicense).then(res => {
128123
assert.strictEqual(res.status, 200);
129124
assert.ok(res.data.allowed);
130-
done();
131-
}).catch(err => done(err));
125+
});
132126
});
133127

134-
it("Should reject nonexistent patron", function (done) {
128+
it("Should reject nonexistent patron", function () {
135129
if (!config?.patreon) this.skip();
136130
mock.onGet(/identity/).reply(200, patreon.invalidIdentity);
137-
getVerifyToken(patreonLicense).then(res => {
131+
return getVerifyToken(patreonLicense).then(res => {
138132
assert.strictEqual(res.status, 200);
139133
assert.ok(!res.data.allowed);
140-
done();
141-
}).catch(err => done(err));
134+
});
142135
});
143136

144-
it("Should accept qualitying former patron", function (done) {
137+
it("Should accept qualitying former patron", function () {
145138
if (!config?.patreon) this.skip();
146139
mock.onGet(/identity/).reply(200, patreon.formerIdentitySucceed);
147-
getVerifyToken(patreonLicense).then(res => {
140+
return getVerifyToken(patreonLicense).then(res => {
148141
assert.strictEqual(res.status, 200);
149142
assert.ok(res.data.allowed);
150-
done();
151-
}).catch(err => done(err));
143+
});
152144
});
153145

154-
it("Should reject unqualitifed former patron", function (done) {
146+
it("Should reject unqualitifed former patron", function () {
155147
if (!config?.patreon) this.skip();
156148
mock.onGet(/identity/).reply(200, patreon.formerIdentityFail);
157-
getVerifyToken(patreonLicense).then(res => {
149+
return getVerifyToken(patreonLicense).then(res => {
158150
assert.strictEqual(res.status, 200);
159151
assert.ok(!res.data.allowed);
160-
done();
161-
}).catch(err => done(err));
152+
});
162153
});
163154

164-
it("Should accept real gumroad key", function (done) {
155+
it("Should accept real gumroad key", () => {
165156
mock.onPost("https://api.gumroad.com/v2/licenses/verify").reply(200, gumroad.licenseSuccess);
166-
getVerifyToken(gumroadLicense).then(res => {
157+
return getVerifyToken(gumroadLicense).then(res => {
167158
assert.strictEqual(res.status, 200);
168159
assert.ok(res.data.allowed);
169-
done();
170-
}).catch(err => done(err));
160+
});
171161
});
172162

173-
it("Should reject fake gumroad key", function (done) {
163+
it("Should reject fake gumroad key", () => {
174164
mock.onPost("https://api.gumroad.com/v2/licenses/verify").reply(200, gumroad.licenseFail);
175-
getVerifyToken(gumroadLicense).then(res => {
165+
return getVerifyToken(gumroadLicense).then(res => {
176166
assert.strictEqual(res.status, 200);
177167
assert.ok(!res.data.allowed);
178-
done();
179-
}).catch(err => done(err));
168+
});
180169
});
181170

182-
it("Should validate local license", function (done) {
171+
it("Should validate local license", () =>
183172
getVerifyToken(localLicense).then(res => {
184173
assert.strictEqual(res.status, 200);
185174
assert.ok(res.data.allowed);
186-
done();
187-
}).catch(err => done(err));
188-
});
175+
})
176+
);
189177
});

0 commit comments

Comments
 (0)