mirror of
https://github.com/logto-io/logto.git
synced 2025-01-27 21:39:16 -05:00
chore(test): fix integration tests
This commit is contained in:
parent
613c0222f8
commit
fbe9f7e89a
3 changed files with 12 additions and 16 deletions
|
@ -68,7 +68,7 @@ class UserRelationQueries extends TwoRelationsQueries<typeof Organizations, type
|
||||||
return this.pool.any<UserWithOrganizationRoles>(sql`
|
return this.pool.any<UserWithOrganizationRoles>(sql`
|
||||||
select
|
select
|
||||||
${users.table}.*,
|
${users.table}.*,
|
||||||
${this.#aggregateRoles('organization_roles')}
|
${this.#aggregateRoles()}
|
||||||
from ${this.table}
|
from ${this.table}
|
||||||
left join ${users.table}
|
left join ${users.table}
|
||||||
on ${fields.userId} = ${users.fields.id}
|
on ${fields.userId} = ${users.fields.id}
|
||||||
|
@ -87,9 +87,9 @@ class UserRelationQueries extends TwoRelationsQueries<typeof Organizations, type
|
||||||
* Build the SQL for aggregating the organization roles with basic information (id and name)
|
* Build the SQL for aggregating the organization roles with basic information (id and name)
|
||||||
* into a JSON array.
|
* into a JSON array.
|
||||||
*
|
*
|
||||||
* @param as The alias of the aggregated roles. Defaults to `roles`.
|
* @param as The alias of the aggregated roles. Defaults to `organizationRoles`.
|
||||||
*/
|
*/
|
||||||
#aggregateRoles(as = 'roles') {
|
#aggregateRoles(as = 'organizationRoles') {
|
||||||
const roles = convertToIdentifiers(OrganizationRoles, true);
|
const roles = convertToIdentifiers(OrganizationRoles, true);
|
||||||
|
|
||||||
return sql`
|
return sql`
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
import { type Role, type Organization } from '@logto/schemas';
|
import { type Role, type Organization, type OrganizationWithRoles } from '@logto/schemas';
|
||||||
|
|
||||||
import { authedAdminApi } from './api.js';
|
import { authedAdminApi } from './api.js';
|
||||||
import { ApiFactory } from './factory.js';
|
import { ApiFactory } from './factory.js';
|
||||||
|
|
||||||
type RoleEntity = {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
type OrganizationWithRoles = Organization & { roles: RoleEntity[] };
|
|
||||||
|
|
||||||
class OrganizationApi extends ApiFactory<Organization, { name: string; description?: string }> {
|
class OrganizationApi extends ApiFactory<Organization, { name: string; description?: string }> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('organizations');
|
super('organizations');
|
||||||
|
@ -26,8 +20,10 @@ class OrganizationApi extends ApiFactory<Organization, { name: string; descripti
|
||||||
await authedAdminApi.delete(`${this.path}/${id}/users/${userId}`);
|
await authedAdminApi.delete(`${this.path}/${id}/users/${userId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async addUserRoles(id: string, userId: string, roleIds: string[]): Promise<void> {
|
async addUserRoles(id: string, userId: string, organizationRoleIds: string[]): Promise<void> {
|
||||||
await authedAdminApi.post(`${this.path}/${id}/users/${userId}/roles`, { json: { roleIds } });
|
await authedAdminApi.post(`${this.path}/${id}/users/${userId}/roles`, {
|
||||||
|
json: { organizationRoleIds },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserRoles(id: string, userId: string): Promise<Role[]> {
|
async getUserRoles(id: string, userId: string): Promise<Role[]> {
|
||||||
|
|
|
@ -205,10 +205,10 @@ describe('organization APIs', () => {
|
||||||
const organization1WithRoles = organizations.find((org) => org.id === organization1.id);
|
const organization1WithRoles = organizations.find((org) => org.id === organization1.id);
|
||||||
assert(organization1WithRoles);
|
assert(organization1WithRoles);
|
||||||
expect(organization1WithRoles.id).toBe(organization1.id);
|
expect(organization1WithRoles.id).toBe(organization1.id);
|
||||||
expect(organization1WithRoles.roles).toContainEqual(
|
expect(organization1WithRoles.organizationRoles).toContainEqual(
|
||||||
expect.objectContaining({ id: role1.id })
|
expect.objectContaining({ id: role1.id })
|
||||||
);
|
);
|
||||||
expect(organization1WithRoles.roles).not.toContainEqual(
|
expect(organization1WithRoles.organizationRoles).not.toContainEqual(
|
||||||
expect.objectContaining({ id: role2.id })
|
expect.objectContaining({ id: role2.id })
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -216,10 +216,10 @@ describe('organization APIs', () => {
|
||||||
const organization2WithRoles = organizations.find((org) => org.id === organization2.id);
|
const organization2WithRoles = organizations.find((org) => org.id === organization2.id);
|
||||||
assert(organization2WithRoles);
|
assert(organization2WithRoles);
|
||||||
expect(organization2WithRoles.id).toBe(organization2.id);
|
expect(organization2WithRoles.id).toBe(organization2.id);
|
||||||
expect(organization2WithRoles.roles).toContainEqual(
|
expect(organization2WithRoles.organizationRoles).toContainEqual(
|
||||||
expect.objectContaining({ id: role1.id })
|
expect.objectContaining({ id: role1.id })
|
||||||
);
|
);
|
||||||
expect(organization2WithRoles.roles).toContainEqual(
|
expect(organization2WithRoles.organizationRoles).toContainEqual(
|
||||||
expect.objectContaining({ id: role2.id })
|
expect.objectContaining({ id: role2.id })
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue