-
-
Notifications
You must be signed in to change notification settings - Fork 466
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 #4645 from logto-io/gao-refactor-integration-test-…
…apis refactor(test): add ApiFactory for integration tests
- Loading branch information
Showing
5 changed files
with
94 additions
and
120 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { authedAdminApi } from './api.js'; | ||
|
||
export class ApiFactory< | ||
Schema extends Record<string, unknown>, | ||
PostData extends Record<string, unknown>, | ||
PatchData extends Record<string, unknown> = Partial<PostData>, | ||
> { | ||
constructor(public readonly path: string) {} | ||
|
||
async create(data: PostData): Promise<Schema> { | ||
return authedAdminApi.post(this.path, { json: data }).json<Schema>(); | ||
} | ||
|
||
async getList(params?: URLSearchParams): Promise<Schema[]> { | ||
return authedAdminApi.get(this.path + '?' + (params?.toString() ?? '')).json<Schema[]>(); | ||
} | ||
|
||
async get(id: string): Promise<Schema> { | ||
return authedAdminApi.get(this.path + '/' + id).json<Schema>(); | ||
} | ||
|
||
async update(id: string, data: PatchData): Promise<Schema> { | ||
return authedAdminApi.patch(this.path + '/' + id, { json: data }).json<Schema>(); | ||
} | ||
|
||
async delete(id: string): Promise<void> { | ||
await authedAdminApi.delete(this.path + '/' + id); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,39 +1,15 @@ | ||
import { type OrganizationScope } from '@logto/schemas'; | ||
|
||
import { authedAdminApi } from './api.js'; | ||
|
||
export const createOrganizationScope = async (name: string, description?: string) => { | ||
return authedAdminApi | ||
.post('organization-scopes', { | ||
json: { | ||
name, | ||
description, | ||
}, | ||
}) | ||
.json<OrganizationScope>(); | ||
}; | ||
|
||
export const getOrganizationScopes = async (params?: URLSearchParams) => { | ||
return authedAdminApi | ||
.get('organization-scopes?' + (params?.toString() ?? '')) | ||
.json<OrganizationScope[]>(); | ||
}; | ||
|
||
export const getOrganizationScope = async (id: string) => { | ||
return authedAdminApi.get('organization-scopes/' + id).json<OrganizationScope>(); | ||
}; | ||
|
||
export const updateOrganizationScope = async (id: string, name: string, description?: string) => { | ||
return authedAdminApi | ||
.patch('organization-scopes/' + id, { | ||
json: { | ||
name, | ||
description, | ||
}, | ||
}) | ||
.json<OrganizationScope>(); | ||
}; | ||
|
||
export const deleteOrganizationScope = async (id: string) => { | ||
return authedAdminApi.delete('organization-scopes/' + id); | ||
}; | ||
import { ApiFactory } from './factory.js'; | ||
|
||
class OrganizationScopeApi extends ApiFactory< | ||
OrganizationScope, | ||
{ name: string; description?: string } | ||
> { | ||
constructor() { | ||
super('organization-scopes'); | ||
} | ||
} | ||
|
||
/** API methods for operating organization template scopes. */ | ||
export const scopeApi = new OrganizationScopeApi(); |
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 |
---|---|---|
@@ -1,37 +1,12 @@ | ||
import { type Organization } from '@logto/schemas'; | ||
|
||
import { authedAdminApi } from './api.js'; | ||
import { ApiFactory } from './factory.js'; | ||
|
||
export const createOrganization = async (name: string, description?: string) => { | ||
return authedAdminApi | ||
.post('organizations', { | ||
json: { | ||
name, | ||
description, | ||
}, | ||
}) | ||
.json<Organization>(); | ||
}; | ||
class OrganizationApi extends ApiFactory<Organization, { name: string; description?: string }> { | ||
constructor() { | ||
super('organizations'); | ||
} | ||
} | ||
|
||
export const getOrganizations = async (params?: URLSearchParams) => { | ||
return authedAdminApi.get('organizations?' + (params?.toString() ?? '')).json<Organization[]>(); | ||
}; | ||
|
||
export const getOrganization = async (id: string) => { | ||
return authedAdminApi.get('organizations/' + id).json<Organization>(); | ||
}; | ||
|
||
export const updateOrganization = async (id: string, name: string, description?: string) => { | ||
return authedAdminApi | ||
.patch('organizations/' + id, { | ||
json: { | ||
name, | ||
description, | ||
}, | ||
}) | ||
.json<Organization>(); | ||
}; | ||
|
||
export const deleteOrganization = async (id: string) => { | ||
return authedAdminApi.delete('organizations/' + id); | ||
}; | ||
/** API methods for operating organizations. */ | ||
export const organizationApi = new OrganizationApi(); |
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
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