Skip to content

Commit 3e1c542

Browse files
committed
add patreon mock
1 parent a1624c8 commit 3e1c542

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

test/cases/tokenUtils.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,16 @@ import axios from "axios";
44
import * as tokenUtils from "../../src/utils/tokenUtils";
55
import MockAdapter from "axios-mock-adapter";
66
let mock: MockAdapter;
7+
import * as patreon from "../mocks/patreonMock";
78

89
const validateToken = (token: string) =>
910
new RegExp(/[A-Za-z0-9]{40}|[A-Za-z0-9-]{35}/).test(token);
1011

11-
const fakePatreonIdentity = {
12-
data: {},
13-
links: {},
14-
included: [
15-
{
16-
attributes: {
17-
is_monthly: true,
18-
currently_entitled_amount_cents: 100,
19-
patron_status: "active_patron",
20-
},
21-
id: "id",
22-
type: "campaign"
23-
}
24-
],
25-
};
26-
2712
describe("tokenUtils test", function() {
2813
before(function() {
2914
mock = new MockAdapter(axios, { onNoMatch: "throwException" });
30-
mock.onPost("https://www.patreon.com/api/oauth2/token").reply(200, {
31-
access_token: "test_access_token",
32-
refresh_token: "test_refresh_token",
33-
expires_in: 3600,
34-
});
35-
mock.onGet(/identity/).reply(200, fakePatreonIdentity);
15+
mock.onPost("https://www.patreon.com/api/oauth2/token").reply(200, patreon.fakeOauth);
16+
mock.onGet(/identity/).reply(200, patreon.fakeIdentity);
3617
});
3718

3819
it("Should be able to create patreon token", function (done) {
@@ -51,7 +32,7 @@ describe("tokenUtils test", function() {
5132
it("Should be able to get patreon identity", function (done) {
5233
if (!config?.patreon) this.skip();
5334
tokenUtils.getPatreonIdentity("fake_access_token").then((result) => {
54-
assert.deepEqual(result, fakePatreonIdentity);
35+
assert.deepEqual(result, patreon.fakeIdentity);
5536
done();
5637
});
5738
});

test/mocks/patreonMock.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const fakeIdentity = {
2+
data: {},
3+
links: {},
4+
included: [
5+
{
6+
attributes: {
7+
is_monthly: true,
8+
currently_entitled_amount_cents: 100,
9+
patron_status: "active_patron",
10+
},
11+
id: "id",
12+
type: "campaign"
13+
}
14+
],
15+
};
16+
17+
export const fakeOauth = {
18+
access_token: "test_access_token",
19+
refresh_token: "test_refresh_token",
20+
expires_in: 3600,
21+
};

0 commit comments

Comments
 (0)