test: Add tests for updateRoleMappings method for saml auth provider

This commit is contained in:
Faruk AYDIN
2024-11-27 17:19:24 +03:00
parent b26e2ecf2e
commit 6e97e023c9
2 changed files with 59 additions and 15 deletions

View File

@@ -133,24 +133,22 @@ class SamlAuthProvider extends Base {
}
async updateRoleMappings(roleMappings) {
return await SamlAuthProvider.transaction(async (trx) => {
await this.$relatedQuery('roleMappings', trx).delete();
await this.$relatedQuery('roleMappings').delete();
if (isEmpty(roleMappings)) {
return [];
}
if (isEmpty(roleMappings)) {
return [];
}
const roleMappingsData = roleMappings.map((roleMapping) => ({
...roleMapping,
samlAuthProviderId: this.id,
}));
const roleMappingsData = roleMappings.map((roleMapping) => ({
...roleMapping,
samlAuthProviderId: this.id,
}));
const newRoleMappings = await RoleMapping.query(trx).insertAndFetch(
roleMappingsData
);
const newRoleMappings = await RoleMapping.query().insertAndFetch(
roleMappingsData
);
return newRoleMappings;
});
return newRoleMappings;
}
}