-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1714 from gettakaro/main-promotion
- Loading branch information
Showing
10 changed files
with
75 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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>({ | ||
|
@@ -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 () { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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). | ||
|
16 changes: 16 additions & 0 deletions
16
packages/lib-db/src/migrations/sql/20241024164331-events-fk-fix.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/test/src/__snapshots__/UserController/Can delete a user.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters