Skip to content

Commit 4761671

Browse files
committed
move patreon mock
1 parent 7457b51 commit 4761671

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

test/cases/tokenUtils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as tokenUtils from "../../src/utils/tokenUtils";
55
import MockAdapter from "axios-mock-adapter";
66
import { validatelicenseKeyRegex } from "../../src/routes/verifyToken";
77
let mock: MockAdapter;
8+
import * as patreon from "../mocks/patreonMock";
89

910
const validateToken = validatelicenseKeyRegex;
1011
const fakePatreonIdentity = {
@@ -26,12 +27,8 @@ const fakePatreonIdentity = {
2627
describe("tokenUtils test", function() {
2728
before(function() {
2829
mock = new MockAdapter(axios, { onNoMatch: "throwException" });
29-
mock.onPost("https://www.patreon.com/api/oauth2/token").reply(200, {
30-
access_token: "test_access_token",
31-
refresh_token: "test_refresh_token",
32-
expires_in: 3600,
33-
});
34-
mock.onGet(/identity/).reply(200, fakePatreonIdentity);
30+
mock.onPost("https://www.patreon.com/api/oauth2/token").reply(200, patreon.fakeOauth);
31+
mock.onGet(/identity/).reply(200, patreon.fakeIdentity);
3532
});
3633

3734
it("Should be able to create patreon token", function (done) {
@@ -50,7 +47,7 @@ describe("tokenUtils test", function() {
5047
it("Should be able to get patreon identity", function (done) {
5148
if (!config?.patreon) this.skip();
5249
tokenUtils.getPatreonIdentity("fake_access_token").then((result) => {
53-
assert.deepEqual(result, fakePatreonIdentity);
50+
assert.deepEqual(result, patreon.fakeIdentity);
5451
done();
5552
});
5653
});

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)