Skip to content

Commit

Permalink
Reformat the tests with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
MytsV committed Aug 21, 2024
1 parent da4118e commit 32ab4ff
Show file tree
Hide file tree
Showing 79 changed files with 5,198 additions and 4,299 deletions.
4 changes: 1 addition & 3 deletions src/lib/core/use-case/list-account-rse-quotas-usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ export default class ListAccountRSEQuotasUseCase
});
}

async generateSourceStream(
requestModel: AuthenticatedRequestModel<AuthenticatedRequestModel<ListAccountRSEQuotasRequest>>,
): Promise<{
async generateSourceStream(requestModel: AuthenticatedRequestModel<AuthenticatedRequestModel<ListAccountRSEQuotasRequest>>): Promise<{
status: 'success' | 'error';
stream?: Transform | Readable | PassThrough | null | undefined;
error?: ListAccountRSEQuotasError | undefined;
Expand Down
71 changes: 35 additions & 36 deletions test/api/account/get-account-info.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { AccountType } from "@/lib/core/entity/rucio";
import { GetAccountInfoRequest } from "@/lib/core/usecase-models/get-account-info-usecase-models";
import { GetAccountInfoControllerParameters } from "@/lib/infrastructure/controller/get-account-info-controller";
import { AccountInfoViewModel } from "@/lib/infrastructure/data/view-model/account";
import appContainer from "@/lib/infrastructure/ioc/container-config";
import CONTROLLERS from "@/lib/infrastructure/ioc/ioc-symbols-controllers";
import { BaseController } from "@/lib/sdk/controller";
import { NextApiResponse } from "next";
import { createHttpMocks } from "test/fixtures/http-fixtures";
import MockRucioServerFactory, { MockEndpoint } from "test/fixtures/rucio-server";
import { AccountType } from '@/lib/core/entity/rucio';
import { GetAccountInfoRequest } from '@/lib/core/usecase-models/get-account-info-usecase-models';
import { GetAccountInfoControllerParameters } from '@/lib/infrastructure/controller/get-account-info-controller';
import { AccountInfoViewModel } from '@/lib/infrastructure/data/view-model/account';
import appContainer from '@/lib/infrastructure/ioc/container-config';
import CONTROLLERS from '@/lib/infrastructure/ioc/ioc-symbols-controllers';
import { BaseController } from '@/lib/sdk/controller';
import { NextApiResponse } from 'next';
import { createHttpMocks } from 'test/fixtures/http-fixtures';
import MockRucioServerFactory, { MockEndpoint } from 'test/fixtures/rucio-server';

describe("Get Account Info", () => {
describe('Get Account Info', () => {
beforeEach(() => {
fetchMock.doMock();
const accountInfoEndpoint: MockEndpoint = {
Expand All @@ -22,40 +22,39 @@ describe("Get Account Info", () => {
'Content-Type': 'application/json',
},
body: JSON.stringify({
"status": "ACTIVE",
"deleted_at": null,
"updated_at": "2023-11-27T17:54:04",
"email": null,
"account_type": "SERVICE",
"suspended_at": null,
"account": "root",
"created_at": "2023-11-27T17:54:04"
})
}
}
status: 'ACTIVE',
deleted_at: null,
updated_at: '2023-11-27T17:54:04',
email: null,
account_type: 'SERVICE',
suspended_at: null,
account: 'root',
created_at: '2023-11-27T17:54:04',
}),
},
};
MockRucioServerFactory.createMockRucioServer(true, [accountInfoEndpoint]);
});

afterEach(() => {
fetchMock.dontMock();
});
it("should return a view model for a valid request to GetAccountInfo feature", async () => {
const { req, res, session } = await createHttpMocks('/api/did-meta', 'GET', {})
const controller = appContainer.get<BaseController<GetAccountInfoControllerParameters, GetAccountInfoRequest>>(CONTROLLERS.GET_ACCOUNT_INFO)

it('should return a view model for a valid request to GetAccountInfo feature', async () => {
const { req, res, session } = await createHttpMocks('/api/did-meta', 'GET', {});

const controller = appContainer.get<BaseController<GetAccountInfoControllerParameters, GetAccountInfoRequest>>(CONTROLLERS.GET_ACCOUNT_INFO);
const controllerParameters: GetAccountInfoControllerParameters = {
response: res as unknown as NextApiResponse,
rucioAuthToken: MockRucioServerFactory.VALID_RUCIO_TOKEN,
account: 'root'
}

await controller.execute(controllerParameters)
expect(res._getStatusCode()).toBe(200)
const data: AccountInfoViewModel = await res._getJSONData()
expect(data.status).toBe('success')
account: 'root',
};

expect(data.accountType).toBe(AccountType.SERVICE)
await controller.execute(controllerParameters);
expect(res._getStatusCode()).toBe(200);
const data: AccountInfoViewModel = await res._getJSONData();
expect(data.status).toBe('success');

expect(data.accountType).toBe(AccountType.SERVICE);
});
});
});
69 changes: 34 additions & 35 deletions test/api/account/switch.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AuthType, Role, SessionUser } from "@/lib/core/entity/auth-models";
import { addOrUpdateSessionUser } from "@/lib/infrastructure/auth/session-utils";
import appContainer from "@/lib/infrastructure/ioc/container-config";
import CONTROLLERS from "@/lib/infrastructure/ioc/ioc-symbols-controllers";
import { ISwitchAccountController } from "@/lib/infrastructure/controller/switch-account-controller";
import { getIronSession } from "iron-session";
import { createMocks } from "node-mocks-http";
import { AuthType, Role, SessionUser } from '@/lib/core/entity/auth-models';
import { addOrUpdateSessionUser } from '@/lib/infrastructure/auth/session-utils';
import appContainer from '@/lib/infrastructure/ioc/container-config';
import CONTROLLERS from '@/lib/infrastructure/ioc/ioc-symbols-controllers';
import { ISwitchAccountController } from '@/lib/infrastructure/controller/switch-account-controller';
import { getIronSession } from 'iron-session';
import { createMocks } from 'node-mocks-http';

describe('Switch Account API Test', () => {
it('should switch to existing account in the session and redirect', async () => {
Expand All @@ -17,9 +17,9 @@ describe('Switch Account API Test', () => {
cookieOptions: {
secure: false,
},
})
});

res.redirect = jest.fn()
res.redirect = jest.fn();

const mockUser: SessionUser = {
rucioIdentity: 'ddmlab',
Expand All @@ -33,7 +33,7 @@ describe('Switch Account API Test', () => {
role: Role.ADMIN,
countryRole: Role.ADMIN,
isLoggedIn: true,
}
};

const mockUser2: SessionUser = {
rucioIdentity: 'maany',
Expand All @@ -47,27 +47,27 @@ describe('Switch Account API Test', () => {
role: Role.ADMIN,
countryRole: Role.ADMIN,
isLoggedIn: true,
}
};

await addOrUpdateSessionUser(session, mockUser2)
await addOrUpdateSessionUser(session, mockUser)
await addOrUpdateSessionUser(session, mockUser2);
await addOrUpdateSessionUser(session, mockUser);

expect(session.user?.rucioIdentity).toBe('ddmlab')
expect(session.user?.rucioIdentity).toBe('ddmlab');

const switchAccountController: ISwitchAccountController = appContainer.get(CONTROLLERS.SWITCH_ACCOUNT)
const switchAccountController: ISwitchAccountController = appContainer.get(CONTROLLERS.SWITCH_ACCOUNT);
await switchAccountController.handle(
session,
res as undefined as NextApiRequest,
mockUser2.rucioIdentity,
mockUser2.rucioAccount,
mockUser2.rucioAuthType,
'/rse'
mockUser2.rucioAuthType,
'/rse',
);
expect(session.user?.rucioIdentity).toBe('maany')
expect(res.redirect).toBeCalledWith('/rse')

expect(session.user?.rucioIdentity).toBe('maany');
expect(res.redirect).toBeCalledWith('/rse');
});
it('should not switch to non-existing account', async() => {
it('should not switch to non-existing account', async () => {
const { req, res } = createMocks({
url: 'http://testhost:3000/api/site-header',
});
Expand All @@ -77,9 +77,9 @@ describe('Switch Account API Test', () => {
cookieOptions: {
secure: false,
},
})
});

res.redirect = jest.fn()
res.redirect = jest.fn();

const mockUser: SessionUser = {
rucioIdentity: 'ddmlab',
Expand All @@ -93,7 +93,7 @@ describe('Switch Account API Test', () => {
role: Role.ADMIN,
countryRole: Role.ADMIN,
isLoggedIn: true,
}
};

const mockUser2: SessionUser = {
rucioIdentity: 'maany',
Expand All @@ -107,23 +107,22 @@ describe('Switch Account API Test', () => {
role: Role.ADMIN,
countryRole: Role.ADMIN,
isLoggedIn: true,
}
};

await addOrUpdateSessionUser(session, mockUser)
await addOrUpdateSessionUser(session, mockUser);

const switchAccountController: ISwitchAccountController = appContainer.get(CONTROLLERS.SWITCH_ACCOUNT)
const switchAccountController: ISwitchAccountController = appContainer.get(CONTROLLERS.SWITCH_ACCOUNT);
await switchAccountController.handle(
session,
res as undefined as NextApiRequest,
mockUser2.rucioIdentity,
mockUser2.rucioAccount,
mockUser2.rucioAuthType,
'/rse'
mockUser2.rucioAuthType,
'/rse',
);

expect(res._getStatusCode()).toBe(500)
const data = JSON.parse(res._getData())
expect(data.error).toBe('Cannot switch to non-existing/logged-in account')

})
});
expect(res._getStatusCode()).toBe(500);
const data = JSON.parse(res._getData());
expect(data.error).toBe('Cannot switch to non-existing/logged-in account');
});
});
80 changes: 39 additions & 41 deletions test/api/auth/login-page-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { setEmptySession } from "@/lib/infrastructure/auth/session-utils";
import appContainer from "@/lib/infrastructure/ioc/container-config";
import CONTROLLERS from "@/lib/infrastructure/ioc/ioc-symbols-controllers";
import { LoginViewModel } from "@/lib/infrastructure/data/view-model/login";
import { getIronSession } from "iron-session";
import { createMocks } from "node-mocks-http";
import { createOIDCProviders, deleteOIDCProviders } from "test/fixtures/oidc-provider-config";
import { BaseController } from "@/lib/sdk/controller";
import { LoginConfigControllerParams } from "@/lib/infrastructure/controller/login-config-controller";
import { setEmptySession } from '@/lib/infrastructure/auth/session-utils';
import appContainer from '@/lib/infrastructure/ioc/container-config';
import CONTROLLERS from '@/lib/infrastructure/ioc/ioc-symbols-controllers';
import { LoginViewModel } from '@/lib/infrastructure/data/view-model/login';
import { getIronSession } from 'iron-session';
import { createMocks } from 'node-mocks-http';
import { createOIDCProviders, deleteOIDCProviders } from 'test/fixtures/oidc-provider-config';
import { BaseController } from '@/lib/sdk/controller';
import { LoginConfigControllerParams } from '@/lib/infrastructure/controller/login-config-controller';

describe('Login Page Config API Test', () => {
beforeEach(() => {
createOIDCProviders()
})
createOIDCProviders();
});
afterEach(() => {
fetchMock.resetMocks();
deleteOIDCProviders()
})
deleteOIDCProviders();
});

it('should present successful LoginViewModel for singleVO', async () => {
const { req, res } = createMocks({
Expand All @@ -27,18 +27,18 @@ describe('Login Page Config API Test', () => {
cookieOptions: {
secure: false,
},
})
await setEmptySession(session, true)
});
await setEmptySession(session, true);

const loginConfigController = appContainer.get<BaseController<LoginConfigControllerParams, void>>(CONTROLLERS.LOGIN_CONFIG)
const loginConfigController = appContainer.get<BaseController<LoginConfigControllerParams, void>>(CONTROLLERS.LOGIN_CONFIG);
await loginConfigController.execute({
session: session,
response: res as any,
});

expect(res._getStatusCode()).toBe(200);
const viewModel: LoginViewModel = JSON.parse(res._getData());

expect(viewModel).toHaveProperty('status');
expect(viewModel.status).toBe('success');
expect(viewModel).toHaveProperty('isLoggedIn');
Expand All @@ -51,7 +51,7 @@ describe('Login Page Config API Test', () => {
expect(viewModel.oidcProviders).toHaveLength(2);
expect(viewModel.oidcProviders[0]).toHaveProperty('name');
expect(viewModel.oidcProviders[0].name).toBe('cern');

expect(viewModel).toHaveProperty('rucioAuthHost');
expect(viewModel.rucioAuthHost).toBe('https://rucio-auth-host.com');

Expand All @@ -61,7 +61,7 @@ describe('Login Page Config API Test', () => {
expect(viewModel.voList).toHaveLength(1);
expect(viewModel.voList[0]).toHaveProperty('name');
expect(viewModel.voList[0].name).toBe('default');
})
});

it('should present successful LoginViewModel for multiVO', async () => {
const { req, res } = createMocks({
Expand All @@ -73,18 +73,17 @@ describe('Login Page Config API Test', () => {
cookieOptions: {
secure: false,
},
})
await setEmptySession(session, true)

process.env['MULTIVO_ENABLED'] = 'true'
process.env['VO_LIST'] = 'vo1,vo2'
process.env['VO_VO1_NAME'] = 'vo1'
process.env['VO_VO1_OIDC_ENABLED'] = 'true'
process.env['VO_VO1_OIDC_PROVIDERS'] = 'cern'
process.env['VO_VO2_NAME'] = 'vo2'
});
await setEmptySession(session, true);

process.env['MULTIVO_ENABLED'] = 'true';
process.env['VO_LIST'] = 'vo1,vo2';
process.env['VO_VO1_NAME'] = 'vo1';
process.env['VO_VO1_OIDC_ENABLED'] = 'true';
process.env['VO_VO1_OIDC_PROVIDERS'] = 'cern';
process.env['VO_VO2_NAME'] = 'vo2';

const loginConfigController = appContainer.get<BaseController<LoginConfigControllerParams, void>>(CONTROLLERS.LOGIN_CONFIG)
const loginConfigController = appContainer.get<BaseController<LoginConfigControllerParams, void>>(CONTROLLERS.LOGIN_CONFIG);
await loginConfigController.execute({
session: session,
response: res as any,
Expand Down Expand Up @@ -116,27 +115,26 @@ describe('Login Page Config API Test', () => {

expect(viewModel.voList[0].oidcProviders[0]).toHaveProperty('name');
expect(viewModel.voList[0].oidcProviders[0].name).toBe('cern');

})
});

it('should present LoginConfigError for invalid or missing config', async () => {
const { req, res } = createMocks({
method: 'POST',
});

const session = await getIronSession(req, res, {
password: 'passwordpasswordpasswordpasswordpassword',
cookieName: 'test-request-session',
cookieOptions: {
secure: false,
},
})
await setEmptySession(session, true)
delete process.env['OIDC_PROVIDERS']
const loginConfigController = appContainer.get<BaseController<LoginConfigControllerParams, void>>(CONTROLLERS.LOGIN_CONFIG)
});

await setEmptySession(session, true);

delete process.env['OIDC_PROVIDERS'];

const loginConfigController = appContainer.get<BaseController<LoginConfigControllerParams, void>>(CONTROLLERS.LOGIN_CONFIG);
await loginConfigController.execute({
session: session,
response: res as any,
Expand All @@ -150,5 +148,5 @@ describe('Login Page Config API Test', () => {

expect(viewModel).toHaveProperty('message');
expect(viewModel.message).toContain('OIDC_PROVIDERS');
})
})
});
});
Loading

0 comments on commit 32ab4ff

Please sign in to comment.