mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
move patreon mock
This commit is contained in:
parent
7457b51aa4
commit
47616711ce
2 changed files with 25 additions and 7 deletions
|
@ -5,6 +5,7 @@ import * as tokenUtils from "../../src/utils/tokenUtils";
|
||||||
import MockAdapter from "axios-mock-adapter";
|
import MockAdapter from "axios-mock-adapter";
|
||||||
import { validatelicenseKeyRegex } from "../../src/routes/verifyToken";
|
import { validatelicenseKeyRegex } from "../../src/routes/verifyToken";
|
||||||
let mock: MockAdapter;
|
let mock: MockAdapter;
|
||||||
|
import * as patreon from "../mocks/patreonMock";
|
||||||
|
|
||||||
const validateToken = validatelicenseKeyRegex;
|
const validateToken = validatelicenseKeyRegex;
|
||||||
const fakePatreonIdentity = {
|
const fakePatreonIdentity = {
|
||||||
|
@ -26,12 +27,8 @@ const fakePatreonIdentity = {
|
||||||
describe("tokenUtils test", function() {
|
describe("tokenUtils test", function() {
|
||||||
before(function() {
|
before(function() {
|
||||||
mock = new MockAdapter(axios, { onNoMatch: "throwException" });
|
mock = new MockAdapter(axios, { onNoMatch: "throwException" });
|
||||||
mock.onPost("https://www.patreon.com/api/oauth2/token").reply(200, {
|
mock.onPost("https://www.patreon.com/api/oauth2/token").reply(200, patreon.fakeOauth);
|
||||||
access_token: "test_access_token",
|
mock.onGet(/identity/).reply(200, patreon.fakeIdentity);
|
||||||
refresh_token: "test_refresh_token",
|
|
||||||
expires_in: 3600,
|
|
||||||
});
|
|
||||||
mock.onGet(/identity/).reply(200, fakePatreonIdentity);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to create patreon token", function (done) {
|
it("Should be able to create patreon token", function (done) {
|
||||||
|
@ -50,7 +47,7 @@ describe("tokenUtils test", function() {
|
||||||
it("Should be able to get patreon identity", function (done) {
|
it("Should be able to get patreon identity", function (done) {
|
||||||
if (!config?.patreon) this.skip();
|
if (!config?.patreon) this.skip();
|
||||||
tokenUtils.getPatreonIdentity("fake_access_token").then((result) => {
|
tokenUtils.getPatreonIdentity("fake_access_token").then((result) => {
|
||||||
assert.deepEqual(result, fakePatreonIdentity);
|
assert.deepEqual(result, patreon.fakeIdentity);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
21
test/mocks/patreonMock.ts
Normal file
21
test/mocks/patreonMock.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
export const fakeIdentity = {
|
||||||
|
data: {},
|
||||||
|
links: {},
|
||||||
|
included: [
|
||||||
|
{
|
||||||
|
attributes: {
|
||||||
|
is_monthly: true,
|
||||||
|
currently_entitled_amount_cents: 100,
|
||||||
|
patron_status: "active_patron",
|
||||||
|
},
|
||||||
|
id: "id",
|
||||||
|
type: "campaign"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fakeOauth = {
|
||||||
|
access_token: "test_access_token",
|
||||||
|
refresh_token: "test_refresh_token",
|
||||||
|
expires_in: 3600,
|
||||||
|
};
|
Loading…
Reference in a new issue