Skip to content

Commit a4a3d1d

Browse files
committed
fix tokenUtils tests, skip if not configured
1 parent 39f3bf8 commit a4a3d1d

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

ci.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
}
7373
},
7474
"patreon": {
75-
"clientID": "testClientID",
75+
"clientId": "testClientID",
7676
"clientSecret": "testClientSecret",
7777
"redirectUri": "http://127.0.0.1/fake/callback"
7878
},

test.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,10 @@
5959
"statusCode": 200
6060
}
6161
},
62+
"patreon": {
63+
"clientId": "testClientID",
64+
"clientSecret": "testClientSecret",
65+
"redirectUri": "http://127.0.0.1/fake/callback"
66+
},
6267
"minReputationToSubmitFiller": -1
6368
}

test/cases/tokenUtils.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
11
import assert from "assert";
2+
import { config } from "../../src/config";
23
import axios from "axios";
34
import * as tokenUtils from "../../src/utils/tokenUtils";
45
import MockAdapter from "axios-mock-adapter";
56
import { validatelicenseKeyRegex } from "../../src/routes/verifyToken";
67
let mock: MockAdapter;
78

89
const validateToken = validatelicenseKeyRegex;
10+
const fakePatreonIdentity = {
11+
data: {},
12+
links: {},
13+
included: [
14+
{
15+
attributes: {
16+
is_monthly: true,
17+
currently_entitled_amount_cents: 100,
18+
patron_status: "active_patron",
19+
},
20+
id: "id",
21+
type: "campaign"
22+
}
23+
],
24+
};
925

1026
describe("tokenUtils test", function() {
1127
before(function() {
1228
mock = new MockAdapter(axios, { onNoMatch: "throwException" });
13-
});
14-
15-
it("Should be able to create patreon token", (done) => {
1629
mock.onPost("https://www.patreon.com/api/oauth2/token").reply(200, {
1730
access_token: "test_access_token",
1831
refresh_token: "test_refresh_token",
1932
expires_in: 3600,
2033
});
34+
mock.onGet(/identity/).reply(200, fakePatreonIdentity);
35+
});
36+
37+
it("Should be able to create patreon token", function (done) {
38+
if (!config?.patreon) this.skip();
2139
tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code").then((licenseKey) => {
2240
assert.ok(validateToken(licenseKey));
2341
done();
@@ -29,34 +47,15 @@ describe("tokenUtils test", function() {
2947
done();
3048
});
3149
});
32-
it("Should be able to get patreon identity", (done) => {
33-
const fakePatreonIdentity = {
34-
data: {},
35-
links: {},
36-
included: [
37-
{
38-
attributes: {
39-
is_monthly: true,
40-
currently_entitled_amount_cents: 100,
41-
patron_status: "active_patron",
42-
},
43-
id: "id",
44-
type: "campaign"
45-
}
46-
],
47-
};
48-
mock.onGet(/identity/).reply(200, fakePatreonIdentity);
50+
it("Should be able to get patreon identity", function (done) {
51+
if (!config?.patreon) this.skip();
4952
tokenUtils.getPatreonIdentity("fake_access_token").then((result) => {
5053
assert.deepEqual(result, fakePatreonIdentity);
5154
done();
5255
});
5356
});
54-
it("Should be able to refresh token", (done) => {
55-
mock.onPost("https://www.patreon.com/api/oauth2/token").reply(200, {
56-
access_token: "test_access_token",
57-
refresh_token: "test_refresh_token",
58-
expires_in: 3600,
59-
});
57+
it("Should be able to refresh token", function (done) {
58+
if (!config?.patreon) this.skip();
6059
tokenUtils.refreshToken(tokenUtils.TokenType.patreon, "fake-licence-Key", "fake_refresh_token").then((result) => {
6160
assert.strictEqual(result, true);
6261
done();

0 commit comments

Comments
 (0)