Skip to content

Commit

Permalink
feat: segregate dev for tests and accept for performance
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu <matthieu.perrin@montreal.ca>
  • Loading branch information
mtlmatt committed Nov 20, 2024
1 parent e19637a commit ba51a3b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 31 deletions.
6 changes: 5 additions & 1 deletion le-taxi-api-tests/config/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export class Configs {
*/
get apiTests() {
return {
rootApiKey: this.cache.get<string>("apiTests.rootApiKey"),
rootApiKey: this.environment.isAcc
? this.cache.get<string>("apiTests.performanceTests.rootApiKey")
: this.cache.get<string>("apiTests.rootApiKey"),
user: this.cache.get<string>("apiTests.user"),
password: this.cache.get<string>("apiTests.password"),
};
Expand Down Expand Up @@ -155,6 +157,8 @@ export let configs: Configs = Configs.instance;

export function getAbsoluteUrl(relative: string): string {
if (configs.environment.isDev) {
return `https://taximtldev.accept.ville.montreal.qc.ca${relative}`;
} else if (configs.environment.isAcc) {
return `https://taximtl.accept.ville.montreal.qc.ca${relative}`;
}

Expand Down
10 changes: 5 additions & 5 deletions le-taxi-api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"load-test-optional-realtime-booking-no-destination": "tsc && node node_modules/artillery/bin/artillery run -o test-optional-realtime-booking-no-destination.report.json src/taxis/loadTests/test-realtime-booking-no-destination.yaml && node node_modules/artillery/bin/artillery report -o test-optional-realtime-booking-no-destination.report.html test-optional-realtime-booking-no-destination.report.json",
"load-test-optional-trigger-many-bad-requests-alert": "tsc && node node_modules/artillery/bin/artillery run src/taxis/loadTests/test-trigger-many-bad-requests-alert.yaml",
"load-test-optional-trigger-many-errors-alert": "tsc && node node_modules/artillery/bin/artillery run src/taxis/loadTests/test-trigger-many-errors-alert.yaml",
"load-test-taxi-position-snapshot-data-dump": "tsc && node node_modules/artillery/bin/artillery run -o test-taxi-position-snapshot-data-dump.report.json src/taxiPositionSnapshotDataDumps/loadTests/test-taxi-position-snapshot-data-dump.yaml && node node_modules/artillery/bin/artillery report -o test-taxi-position-snapshot-data-dump.report.html test-taxi-position-snapshot-data-dump.report.json",
"load-test-taxi-grid": "tsc && node node_modules/artillery/bin/artillery run -o test-taxi-grid.report.json src/taxis/loadTests/test-taxi-grid.yaml && node node_modules/artillery/bin/artillery report -o test-taxi-grid.report.html test-taxi-grid.report.json",
"load-test-osrm": "tsc && node node_modules/artillery/bin/artillery run -o test-osrm.report.json src/osrm/loadTests/test-osrm.yaml && node node_modules/artillery/bin/artillery report -o test-osrm.report.html test-osrm.report.json",
"generate-load-test-shared-state": "env NODE_ENV=development npm run launch-generate-load-test-shared-state",
"generate-integration-tests-shared-state": "env NODE_ENV=development npm run launch-generate-integration-tests-shared-state",
"load-test-taxi-position-snapshot-data-dump": "tsc && env NODE_ENV=acceptation node node_modules/artillery/bin/artillery run -o test-taxi-position-snapshot-data-dump.report.json src/taxiPositionSnapshotDataDumps/loadTests/test-taxi-position-snapshot-data-dump.yaml && node node_modules/artillery/bin/artillery report -o test-taxi-position-snapshot-data-dump.report.html test-taxi-position-snapshot-data-dump.report.json",
"load-test-taxi-grid": "tsc && env NODE_ENV=acceptation node node_modules/artillery/bin/artillery run -o test-taxi-grid.report.json src/taxis/loadTests/test-taxi-grid.yaml && node node_modules/artillery/bin/artillery report -o test-taxi-grid.report.html test-taxi-grid.report.json",
"load-test-osrm": "tsc &&node node_modules/artillery/bin/artillery run -o test-osrm.report.json src/osrm/loadTests/test-osrm.yaml && node node_modules/artillery/bin/artillery report -o test-osrm.report.html test-osrm.report.json",
"generate-load-test-shared-state": "env NODE_ENV=acceptation npm run launch-generate-load-test-shared-state",
"generate-integration-tests-shared-state": "env NODE_ENV=acceptation npm run launch-generate-integration-tests-shared-state",
"clean": "rimraf src/**/*.js src/**/*.js.map",
"watch": "npm run clean && tsc --watch --pretty",
"lint": "npm run prettier && npm run tslint",
Expand Down
84 changes: 59 additions & 25 deletions le-taxi-api-tests/src/users/user.apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,68 @@
// Licensed under the AGPL-3.0 license.
// See LICENSE file in the project root for full license information.
import { v4 as uuidv4 } from 'uuid';
import { configs } from '../../config/configs';
import { aFewSeconds } from '../shared/commonTests/testUtil';
import { UserRole } from '../shared/commonTests/UserRole';
import { getTestRunId } from '../shared/e2eTesting/testRunId';
import { IUser } from '../shared/taxiRegistryDtos/taxiRegistryDtos';
import { v4 as uuidv4 } from "uuid";
import { configs } from "../../config/configs";
import { aFewSeconds } from "../shared/commonTests/testUtil";
import { UserRole } from "../shared/commonTests/UserRole";
import { getTestRunId } from "../shared/e2eTesting/testRunId";
import { IUser } from "../shared/taxiRegistryDtos/taxiRegistryDtos";
import {
getSimpleUsingAccessToken,
getTaxiRegistry,
postSimple,
postTaxiRegistry,
putTaxiRegistry
} from '../shared/taxiRegistryHttp/taxiRegistryHttp';
import { getImmutableUserApiKey } from './user.sharedFixture';
import { copyUserTemplate } from './userDto.template';
putTaxiRegistry,
} from "../shared/taxiRegistryHttp/taxiRegistryHttp";
import { getImmutableUserApiKey } from "./user.sharedFixture";
import { copyUserTemplate } from "./userDto.template";

const rootApiKey = configs.apiTests.rootApiKey;
console.log("rootApiKey", rootApiKey);

export async function createPromotedOperator(dto: IUser, apiKey?: string) {
if (dto.email === 'auto') dto.email = generateAutoEmail();
if (dto.public_id === 'auto') dto.public_id = uuidv4();

const userResponse = await postTaxiRegistry('/api/legacy-web/users', dto, apiKey, rootApiKey);
if (dto.email === "auto") dto.email = generateAutoEmail();
if (dto.public_id === "auto") dto.public_id = uuidv4();

const userResponse = await postTaxiRegistry(
"/api/legacy-web/users",
dto,
apiKey,
rootApiKey
);
await aFewSeconds(configs.inquiries.delayToExceedPromotion);
return userResponse.body;
}

export async function createUser(dto: IUser, apiKey?: string) {
if (dto.email === 'auto') dto.email = generateAutoEmail();
if (dto.public_id === 'auto') dto.public_id = dto.role === UserRole.Operator ? uuidv4() : null;

const userResponse = await postTaxiRegistry('/api/legacy-web/users', dto, apiKey, rootApiKey);
if (dto.email === "auto") dto.email = generateAutoEmail();
if (dto.public_id === "auto")
dto.public_id = dto.role === UserRole.Operator ? uuidv4() : null;

const userResponse = await postTaxiRegistry(
"/api/legacy-web/users",
dto,
apiKey,
rootApiKey
);
return userResponse.body;
}

export async function updateUser(dto: IUser, apiKey?: string) {
const userResponse = await putTaxiRegistry('/api/legacy-web/users', dto, apiKey, rootApiKey);
const userResponse = await putTaxiRegistry(
"/api/legacy-web/users",
dto,
apiKey,
rootApiKey
);
return userResponse.body;
}

export async function getUser(id: string, apiKey?: string): Promise<IUser> {
const userResponse = await getTaxiRegistry(`/api/legacy-web/users?id=${id}`, apiKey, rootApiKey);
const userResponse = await getTaxiRegistry(
`/api/legacy-web/users?id=${id}`,
apiKey,
rootApiKey
);
return userResponse.body[0];
}

Expand All @@ -50,16 +71,19 @@ export async function login(dto?: any): Promise<any> {
// tslint:disable-next-line: no-parameter-reassignment
dto = {
login: configs.apiTests.user,
password: configs.apiTests.password
password: configs.apiTests.password,
};
}

const userResponse = await postSimple('/api/legacy-web/login/DoLogin', dto);
const userResponse = await postSimple("/api/legacy-web/login/DoLogin", dto);
return userResponse;
}

export async function getLoginUserinfo(accessToken?: string): Promise<any> {
const userResponse = await getSimpleUsingAccessToken('/api/legacy-web/login/userinfo', accessToken);
const userResponse = await getSimpleUsingAccessToken(
"/api/legacy-web/login/userinfo",
accessToken
);
return userResponse;
}

Expand All @@ -83,10 +107,20 @@ export async function updatePassword(dto?: (x: any) => void, apiKey?: string) {

async function putAccountApikey(dto: any, apiKey?: string) {
const defaultApiKey = await getImmutableUserApiKey(UserRole.Manager);
return await putTaxiRegistry('/api/legacy-web/users/apikey', dto, apiKey, defaultApiKey);
return await putTaxiRegistry(
"/api/legacy-web/users/apikey",
dto,
apiKey,
defaultApiKey
);
}

async function putAccountPassword(dto: any, apiKey?: string) {
const defaultApiKey = await getImmutableUserApiKey(UserRole.Manager);
return await putTaxiRegistry('/api/legacy-web/users/password', dto, apiKey, defaultApiKey);
return await putTaxiRegistry(
"/api/legacy-web/users/password",
dto,
apiKey,
defaultApiKey
);
}

0 comments on commit ba51a3b

Please sign in to comment.