Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Merge development into main #1714

Merged
merged 8 commits into from
Oct 24, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ const group = 'UserController';

interface IUserSetup {
user: UserOutputDTO;
userClient: Client;
}

const userSetup = async function (this: IntegrationTest<IUserSetup>) {
const password = faker.internet.password();
const user = await this.client.user.userControllerCreate({
name: 'Test user',
idpId: 'test',
email: '[email protected]',
password: 'test',
email: `test-${faker.internet.email()}`,
password,
});
return { user: user.data.data };

const userClient = new Client({
auth: { username: user.data.data.email, password },
url: integrationConfig.get('host'),
});
await userClient.login();

return { user: user.data.data, userClient };
};

async function multiRolesSetup(client: Client) {
Expand Down Expand Up @@ -99,7 +107,7 @@ const tests = [

return userRes;
},
filteredFields: ['idpId', 'roleId', 'userId', 'lastSeen'],
filteredFields: ['idpId', 'roleId', 'userId', 'lastSeen', 'email'],
}),
// Repro for https://github.com/gettakaro/takaro/issues/1013
new IntegrationTest<IUserSetup>({
Expand Down Expand Up @@ -247,6 +255,27 @@ const tests = [
}
},
}),
new IntegrationTest<IUserSetup>({
group,
snapshot: true,
name: 'Can delete a user',
setup: userSetup,
test: async function () {
// This is a bug repro, when you delete a user that has events, a FK constraint error is thrown
const role = (await this.client.role.roleControllerSearch({ filters: { name: ['root'] } })).data.data[0];
await this.client.user.userControllerAssignRole(this.setupData.user.id, role.id);
await this.setupData.userClient.module.moduleControllerCreate({ name: 'blabla', description: 'blabla' });
// So, let's ensure there's an event for this user
const events = await this.client.event.eventControllerSearch({
filters: { actingUserId: [this.setupData.user.id] },
});
expect(events.data.data.length).to.be.greaterThan(0, 'No events found for user');

// Then delete the user
const res = await this.client.user.userControllerRemove(this.setupData.user.id);
return res;
},
}),
];

describe(group, function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - 4afae5c5b76ff57e864ef0e1e163c55f4208cdee
* The version of the OpenAPI document: development - 7db8bf613f31d89cbf65ef6edccefa26bf129b15
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - 4afae5c5b76ff57e864ef0e1e163c55f4208cdee
* The version of the OpenAPI document: development - 7db8bf613f31d89cbf65ef6edccefa26bf129b15
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - 4afae5c5b76ff57e864ef0e1e163c55f4208cdee
* The version of the OpenAPI document: development - 7db8bf613f31d89cbf65ef6edccefa26bf129b15
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - 4afae5c5b76ff57e864ef0e1e163c55f4208cdee
* The version of the OpenAPI document: development - 7db8bf613f31d89cbf65ef6edccefa26bf129b15
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-apiclient/src/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Takaro app-api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: development - 4afae5c5b76ff57e864ef0e1e163c55f4208cdee
* The version of the OpenAPI document: development - 7db8bf613f31d89cbf65ef6edccefa26bf129b15
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
16 changes: 16 additions & 0 deletions packages/lib-db/src/migrations/sql/20241024164331-events-fk-fix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
// When player, module, gameserver or userId is deleted, keep the event
await knex.schema.alterTable('events', (table) => {
table.dropForeign(['actingUserId']);
table.dropForeign(['actingModuleId']);
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable('events', (table) => {
table.foreign('actingUserId').references('id').inTable('users').onDelete('CASCADE');
table.foreign('actingModuleId').references('id').inTable('modules').onDelete('CASCADE');
});
}
4 changes: 3 additions & 1 deletion packages/lib-http/src/middleware/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export async function ErrorHandler(
// @ts-expect-error Error typing is weird in ts... but we validate during runtime so should be OK
const validationErrors = originalError['errors'] as ValidationError[];
parsedError = new errors.ValidationError('Validation error', validationErrors);
log.warn('⚠️ Validation errror', { details: validationErrors.map((e) => JSON.stringify(e.target, null, 2)) });
log.warn('⚠️ Validation errror', {
details: validationErrors.map((e) => JSON.stringify(e.constraints, null, 2)),
});
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"body": {
"meta": {},
"data": {}
},
"status": 200,
"test": {
"group": "UserController",
"snapshot": true,
"name": "Can delete a user",
"expectedStatus": 200,
"filteredFields": [],
"standardEnvironment": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"idpId",
"roleId",
"userId",
"lastSeen"
"lastSeen",
"email"
],
"expectedStatus": 200,
"standardEnvironment": true
Expand Down
Loading