mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Implemented strict mode for the project (broken tests, hundreds of @ts-ignore and new errors are included) [skip ci]
This commit is contained in:
committed by
SleepWalker
parent
10e8b77acf
commit
96049ad4ad
@@ -2,7 +2,7 @@ import expect from 'app/test/unexpected';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import request from 'app/services/request';
|
||||
import signup from 'app/services/api/signup';
|
||||
import * as signup from 'app/services/api/signup';
|
||||
|
||||
describe('signup api', () => {
|
||||
describe('#register', () => {
|
||||
@@ -46,9 +46,7 @@ describe('signup api', () => {
|
||||
});
|
||||
|
||||
describe('#activate', () => {
|
||||
const params = {
|
||||
key: 'key',
|
||||
};
|
||||
const key = 'key';
|
||||
|
||||
beforeEach(() => {
|
||||
sinon.stub(request, 'post').named('request.post');
|
||||
@@ -59,21 +57,21 @@ describe('signup api', () => {
|
||||
});
|
||||
|
||||
it('should post to confirmation api', () => {
|
||||
signup.activate(params);
|
||||
signup.activate(key);
|
||||
|
||||
expect(request.post, 'to have a call satisfying', [
|
||||
'/api/signup/confirm',
|
||||
params,
|
||||
{ key },
|
||||
{},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should disable any token', () => {
|
||||
signup.activate(params);
|
||||
signup.activate(key);
|
||||
|
||||
expect(request.post, 'to have a call satisfying', [
|
||||
'/api/signup/confirm',
|
||||
params,
|
||||
{ key },
|
||||
{ token: null },
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1,28 +1,18 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
import expect from 'app/test/unexpected';
|
||||
import sinon from 'sinon';
|
||||
import sinon, { SinonFakeServer } from 'sinon';
|
||||
|
||||
import request from 'app/services/request';
|
||||
import * as authentication from 'app/services/api/authentication';
|
||||
import * as accounts from 'app/services/api/accounts';
|
||||
|
||||
describe('authentication api', () => {
|
||||
let server;
|
||||
let server: SinonFakeServer;
|
||||
|
||||
beforeEach(() => {
|
||||
server = sinon.createFakeServer({
|
||||
server = sinon.fakeServer.create({
|
||||
autoRespond: true,
|
||||
});
|
||||
|
||||
['get', 'post'].forEach(method => {
|
||||
server[method] = (url, resp = {}, status = 200, headers = {}) => {
|
||||
server.respondWith(method, url, [
|
||||
status,
|
||||
{ 'Content-Type': 'application/json', ...headers },
|
||||
JSON.stringify(resp),
|
||||
]);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -156,12 +146,16 @@ describe('authentication api', () => {
|
||||
});
|
||||
|
||||
it('resolves with new token and user object', async () => {
|
||||
server.post('/api/authentication/refresh-token', {
|
||||
access_token: newToken,
|
||||
refresh_token: validRefreshToken,
|
||||
success: true,
|
||||
expires_in: 50000,
|
||||
});
|
||||
server.respondWith(
|
||||
'POST',
|
||||
'/api/authentication/refresh-token',
|
||||
JSON.stringify({
|
||||
access_token: newToken,
|
||||
refresh_token: validRefreshToken,
|
||||
success: true,
|
||||
expires_in: 50000,
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(
|
||||
authentication.validateToken(...validateTokenArgs),
|
||||
@@ -178,7 +172,11 @@ describe('authentication api', () => {
|
||||
|
||||
it('rejects if token request failed', () => {
|
||||
const error = { error: 'Unexpected error example' };
|
||||
server.post('/api/authentication/refresh-token', error, 500);
|
||||
server.respondWith('POST', '/api/authentication/refresh-token', [
|
||||
500,
|
||||
[],
|
||||
JSON.stringify(error),
|
||||
]);
|
||||
|
||||
return expect(
|
||||
authentication.validateToken(...validateTokenArgs),
|
||||
@@ -205,12 +203,16 @@ describe('authentication api', () => {
|
||||
});
|
||||
|
||||
it('resolves with new token and user object', async () => {
|
||||
server.post('/api/authentication/refresh-token', {
|
||||
access_token: newToken,
|
||||
refresh_token: validRefreshToken,
|
||||
success: true,
|
||||
expires_in: 50000,
|
||||
});
|
||||
server.respondWith(
|
||||
'POST',
|
||||
'/api/authentication/refresh-token',
|
||||
JSON.stringify({
|
||||
access_token: newToken,
|
||||
refresh_token: validRefreshToken,
|
||||
success: true,
|
||||
expires_in: 50000,
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(
|
||||
authentication.validateToken(...validateTokenArgs),
|
||||
@@ -227,7 +229,11 @@ describe('authentication api', () => {
|
||||
|
||||
it('rejects if token request failed', () => {
|
||||
const error = { error: 'Unexpected error example' };
|
||||
server.post('/api/authentication/refresh-token', error, 500);
|
||||
server.respondWith('POST', '/api/authentication/refresh-token', [
|
||||
500,
|
||||
[],
|
||||
JSON.stringify(error),
|
||||
]);
|
||||
|
||||
return expect(
|
||||
authentication.validateToken(...validateTokenArgs),
|
||||
|
||||
@@ -8,13 +8,13 @@ export type Scope =
|
||||
| 'account_info'
|
||||
| 'account_email';
|
||||
|
||||
export type Client = {
|
||||
export interface Client {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type OauthAppResponse = {
|
||||
export interface OauthAppResponse {
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
type: ApplicationType;
|
||||
@@ -27,9 +27,9 @@ export type OauthAppResponse = {
|
||||
redirectUri?: string;
|
||||
// fields for 'minecraft-server' type
|
||||
minecraftServerIp?: string;
|
||||
};
|
||||
}
|
||||
|
||||
type OauthRequestData = {
|
||||
interface OauthRequestData {
|
||||
client_id: string;
|
||||
redirect_uri: string;
|
||||
response_type: string;
|
||||
@@ -38,37 +38,43 @@ type OauthRequestData = {
|
||||
prompt: string;
|
||||
login_hint?: string;
|
||||
state?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type OauthData = {
|
||||
export interface OauthData {
|
||||
clientId: string;
|
||||
redirectUrl: string;
|
||||
responseType: string;
|
||||
description?: string;
|
||||
scope: string;
|
||||
// TODO: why prompt is not nullable?
|
||||
prompt: string; // comma separated list of 'none' | 'consent' | 'select_account';
|
||||
loginHint?: string;
|
||||
state?: string;
|
||||
};
|
||||
}
|
||||
|
||||
type FormPayloads = {
|
||||
export interface OAuthValidateResponse {
|
||||
session: {
|
||||
scopes: Scope[];
|
||||
};
|
||||
client: Client;
|
||||
oAuth: {}; // TODO: improve typing
|
||||
}
|
||||
|
||||
interface FormPayloads {
|
||||
name?: string;
|
||||
description?: string;
|
||||
websiteUrl?: string;
|
||||
redirectUri?: string;
|
||||
minecraftServerIp?: string;
|
||||
};
|
||||
}
|
||||
|
||||
const api = {
|
||||
validate(oauthData: OauthData) {
|
||||
return request
|
||||
.get<{
|
||||
session: {
|
||||
scopes: Scope[];
|
||||
};
|
||||
client: Client;
|
||||
oAuth: {};
|
||||
}>('/api/oauth2/v1/validate', getOAuthRequest(oauthData))
|
||||
.get<OAuthValidateResponse>(
|
||||
'/api/oauth2/v1/validate',
|
||||
getOAuthRequest(oauthData),
|
||||
)
|
||||
.catch(handleOauthParamsValidation);
|
||||
},
|
||||
|
||||
|
||||
@@ -10,7 +10,12 @@ describe('services/api/options', () => {
|
||||
sinon
|
||||
.stub(request, 'get')
|
||||
.named('request.get')
|
||||
.returns(Promise.resolve(expectedResp));
|
||||
.returns(
|
||||
Promise.resolve({
|
||||
originalResponse: new Response(),
|
||||
...expectedResp,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -1,33 +1,37 @@
|
||||
import request from 'app/services/request';
|
||||
import request, { Resp } from 'app/services/request';
|
||||
|
||||
import { OAuthResponse } from './authentication';
|
||||
|
||||
export default {
|
||||
register({
|
||||
email = '',
|
||||
username = '',
|
||||
password = '',
|
||||
rePassword = '',
|
||||
rulesAgreement = false,
|
||||
lang = '',
|
||||
captcha = '',
|
||||
}) {
|
||||
return request.post(
|
||||
'/api/signup',
|
||||
{ email, username, password, rePassword, rulesAgreement, lang, captcha },
|
||||
{ token: null },
|
||||
);
|
||||
},
|
||||
interface RegisterParams {
|
||||
email?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
rePassword?: string;
|
||||
rulesAgreement?: boolean;
|
||||
lang?: string;
|
||||
captcha?: string;
|
||||
}
|
||||
|
||||
activate({ key = '' }) {
|
||||
return request.post<OAuthResponse>(
|
||||
'/api/signup/confirm',
|
||||
{ key },
|
||||
{ token: null },
|
||||
);
|
||||
},
|
||||
export function register({
|
||||
email = '',
|
||||
username = '',
|
||||
password = '',
|
||||
rePassword = '',
|
||||
rulesAgreement = false,
|
||||
lang = '',
|
||||
captcha = '',
|
||||
}: RegisterParams): Promise<Resp<void>> {
|
||||
return request.post(
|
||||
'/api/signup',
|
||||
{ email, username, password, rePassword, rulesAgreement, lang, captcha },
|
||||
{ token: null },
|
||||
);
|
||||
}
|
||||
|
||||
resendActivation({ email = '', captcha }) {
|
||||
return request.post('/api/signup/repeat-message', { email, captcha });
|
||||
},
|
||||
};
|
||||
export function activate(key: string = ''): Promise<Resp<OAuthResponse>> {
|
||||
return request.post('/api/signup/confirm', { key }, { token: null });
|
||||
}
|
||||
|
||||
export function resendActivation(email: string = '', captcha: string = '') {
|
||||
return request.post('/api/signup/repeat-message', { email, captcha });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user