Files
meteor/packages/github-oauth/github-oauth_tests.js
Nacho Codoñer 44b0a25923 use better naming
2024-05-09 16:19:43 +02:00

35 lines
1.3 KiB
JavaScript

Tinytest.addAsync(
'github-oauth - run service oauth with mocked flow as expected',
async function (test) {
const oauthMock = mockBehaviours(OAuth, {
_fetch: () => Promise.resolve({ json: () => ([{ access_token: 'testToken', email: { primary: 'email' } }])}),
});
const service = 'github';
const serviceMockConfig = { service };
const mockConfig = { clientId: "test", secret: "test", loginStyle: "popup" };
if (Meteor.isServer) {
await ServiceConfiguration.configurations.upsertAsync(serviceMockConfig, { $set: mockConfig });
const result = await OAuthTest.registeredServices[service].handleOauthRequest({});
test.isTrue(!!result?.serviceData, 'should return mocked result');
test.equal(
oauthMock.mockedRuns.map(({ name }) => name),
['_redirectUri','_fetch','_fetch','_fetch','sealSecret'],
'should run mock oauth behaviors',
);
} else if (Meteor.isClient) {
ServiceConfiguration.configurations.insert({ ...serviceMockConfig, ...mockConfig });
Github.requestCredential({});
test.equal(
oauthMock.mockedRuns.map(({ name }) => name),
['_loginStyle', '_redirectUri', '_stateParam', 'launchLogin'],
'should run mock oauth behaviors',
);
}
oauthMock.stop();
return Promise.resolve();
},
);