Skip to content

Commit

Permalink
refactor: NicoliveClient.requestAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
koizuka committed Apr 25, 2024
1 parent f3390ff commit aa1d659
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 221 deletions.
15 changes: 7 additions & 8 deletions app/services/nicolive-program/NicoliveClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fetchMock from 'fetch-mock';
import { WrappedResult } from './NicoliveClient';
import { NicoliveClient, parseMaxQuality, WrappedResult } from './NicoliveClient';
import { Communities, Community } from './ResponseTypes';
const { NicoliveClient, parseMaxQuality } = require('./NicoliveClient');

jest.mock('services/i18n', () => ({
$t: (x: any) => x,
Expand All @@ -28,8 +27,7 @@ describe('parseMaxQuality', () => {
height,
fps,
});
}
);
});
});

test('constructor', () => {
Expand Down Expand Up @@ -160,7 +158,8 @@ const suites: Suite[] = [

suites.forEach((suite: Suite) => {
test(`dataを取り出して返す - ${suite.name}`, async () => {
const client = new NicoliveClient();
// niconicoSession を与えないと、実行時の main process の cookieから取ろうとして失敗するので差し替える
const client = new NicoliveClient({ niconicoSession: 'dummy' });

fetchMock[suite.method.toLowerCase()](suite.base + suite.path, dummyBody);
const result = await client[suite.name](...(suite.args || []));
Expand Down Expand Up @@ -251,7 +250,7 @@ function setupMock() {
loadURL(url: string) {
this.url = url;
for (const cb of this.webContentsCallbacks) {
cb({ preventDefault() { } }, url);
cb({ preventDefault() {} }, url);
}
}
close = jest.fn().mockImplementation(() => {
Expand Down Expand Up @@ -284,7 +283,7 @@ function setupMock() {
},
},
ipcRenderer: {
send() { },
send() {},
},
}));

Expand Down Expand Up @@ -437,4 +436,4 @@ describe('webviews', () => {
});
});

// TODO add test for konomiTags, userFollow APIs
// TODO add test for konomiTags, userFollow APIs
Loading

0 comments on commit aa1d659

Please sign in to comment.