Skip to content

Commit 981895a

Browse files
authored
subtenant support for the tenant functions (#618)
1 parent 17782c6 commit 981895a

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

lib/management/tenant.test.ts

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,43 @@ describe('Management Tenant', () => {
8080
response: httpResponse,
8181
});
8282
});
83+
84+
it('should send the correct request with parent parameter', async () => {
85+
const httpResponse = {
86+
ok: true,
87+
json: () => mockTenantCreateResponse,
88+
clone: () => ({
89+
json: () => Promise.resolve(mockTenantCreateResponse),
90+
}),
91+
status: 200,
92+
};
93+
mockHttpClient.post.mockResolvedValue(httpResponse);
94+
95+
const resp: SdkResponse<CreateTenantResponse> = await management.tenant.create(
96+
'child-tenant',
97+
['child.example.com'],
98+
{ type: 'department' },
99+
false,
100+
false,
101+
'parent-tenant-id',
102+
);
103+
104+
expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.tenant.create, {
105+
name: 'child-tenant',
106+
selfProvisioningDomains: ['child.example.com'],
107+
customAttributes: { type: 'department' },
108+
enforceSSO: false,
109+
disabled: false,
110+
parent: 'parent-tenant-id',
111+
});
112+
113+
expect(resp).toEqual({
114+
code: 200,
115+
data: mockTenantCreateResponse,
116+
ok: true,
117+
response: httpResponse,
118+
});
119+
});
83120
});
84121

85122
describe('createWithId', () => {
@@ -119,6 +156,45 @@ describe('Management Tenant', () => {
119156
response: httpResponse,
120157
});
121158
});
159+
160+
it('should send the correct request with parent parameter', async () => {
161+
const httpResponse = {
162+
ok: true,
163+
json: () => {},
164+
clone: () => ({
165+
json: () => Promise.resolve({}),
166+
}),
167+
status: 200,
168+
};
169+
mockHttpClient.post.mockResolvedValue(httpResponse);
170+
171+
const resp: SdkResponse<CreateTenantResponse> = await management.tenant.createWithId(
172+
'custom-child-id',
173+
'child-tenant',
174+
['child.example.com'],
175+
{ type: 'department' },
176+
false,
177+
false,
178+
'parent-tenant-id',
179+
);
180+
181+
expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.tenant.create, {
182+
id: 'custom-child-id',
183+
name: 'child-tenant',
184+
selfProvisioningDomains: ['child.example.com'],
185+
customAttributes: { type: 'department' },
186+
enforceSSO: false,
187+
disabled: false,
188+
parent: 'parent-tenant-id',
189+
});
190+
191+
expect(resp).toEqual({
192+
code: 200,
193+
data: {},
194+
ok: true,
195+
response: httpResponse,
196+
});
197+
});
122198
});
123199

124200
describe('update', () => {
@@ -240,6 +316,76 @@ describe('Management Tenant', () => {
240316
});
241317
});
242318

319+
describe('searchAll', () => {
320+
it('should send the correct request and receive correct response', async () => {
321+
const httpResponse = {
322+
ok: true,
323+
json: () => mockAllTenantsResponse,
324+
clone: () => ({
325+
json: () => Promise.resolve(mockAllTenantsResponse),
326+
}),
327+
status: 200,
328+
};
329+
mockHttpClient.post.mockResolvedValue(httpResponse);
330+
331+
const resp: SdkResponse<Tenant[]> = await management.tenant.searchAll(
332+
['t1', 't2'],
333+
['name1'],
334+
['domain1.com'],
335+
{ customAttr: 'value' },
336+
);
337+
338+
expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.tenant.searchAll, {
339+
tenantIds: ['t1', 't2'],
340+
tenantNames: ['name1'],
341+
tenantSelfProvisioningDomains: ['domain1.com'],
342+
customAttributes: { customAttr: 'value' },
343+
});
344+
345+
expect(resp).toEqual({
346+
code: 200,
347+
data: mockTenants,
348+
ok: true,
349+
response: httpResponse,
350+
});
351+
});
352+
353+
it('should send the correct request with parentTenantId parameter', async () => {
354+
const httpResponse = {
355+
ok: true,
356+
json: () => mockAllTenantsResponse,
357+
clone: () => ({
358+
json: () => Promise.resolve(mockAllTenantsResponse),
359+
}),
360+
status: 200,
361+
};
362+
mockHttpClient.post.mockResolvedValue(httpResponse);
363+
364+
const resp: SdkResponse<Tenant[]> = await management.tenant.searchAll(
365+
undefined,
366+
undefined,
367+
undefined,
368+
undefined,
369+
'parent-tenant-id',
370+
);
371+
372+
expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.tenant.searchAll, {
373+
tenantIds: undefined,
374+
tenantNames: undefined,
375+
tenantSelfProvisioningDomains: undefined,
376+
customAttributes: undefined,
377+
parentTenantId: 'parent-tenant-id',
378+
});
379+
380+
expect(resp).toEqual({
381+
code: 200,
382+
data: mockTenants,
383+
ok: true,
384+
response: httpResponse,
385+
});
386+
});
387+
});
388+
243389
describe('getSettings', () => {
244390
it('should send the correct request and receive correct response', async () => {
245391
const httpResponse = {

lib/management/tenant.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const withTenant = (httpClient: HttpClient) => ({
1919
customAttributes?: Record<string, AttributesTypes>,
2020
enforceSSO?: boolean,
2121
disabled?: boolean,
22+
parent?: string,
2223
): Promise<SdkResponse<CreateTenantResponse>> =>
2324
transformResponse(
2425
httpClient.post(apiPaths.tenant.create, {
@@ -27,6 +28,7 @@ const withTenant = (httpClient: HttpClient) => ({
2728
customAttributes,
2829
enforceSSO,
2930
disabled,
31+
parent,
3032
}),
3133
),
3234
createWithId: (
@@ -36,6 +38,7 @@ const withTenant = (httpClient: HttpClient) => ({
3638
customAttributes?: Record<string, AttributesTypes>,
3739
enforceSSO?: boolean,
3840
disabled?: boolean,
41+
parent?: string,
3942
): Promise<SdkResponse<never>> =>
4043
transformResponse(
4144
httpClient.post(apiPaths.tenant.create, {
@@ -45,6 +48,7 @@ const withTenant = (httpClient: HttpClient) => ({
4548
customAttributes,
4649
enforceSSO,
4750
disabled,
51+
parent,
4852
}),
4953
),
5054
update: (
@@ -84,13 +88,15 @@ const withTenant = (httpClient: HttpClient) => ({
8488
names?: string[],
8589
selfProvisioningDomains?: string[],
8690
customAttributes?: Record<string, AttributesTypes>,
91+
parentTenantId?: string,
8792
): Promise<SdkResponse<Tenant[]>> =>
8893
transformResponse<MultipleTenantResponse, Tenant[]>(
8994
httpClient.post(apiPaths.tenant.searchAll, {
9095
tenantIds: ids,
9196
tenantNames: names,
9297
tenantSelfProvisioningDomains: selfProvisioningDomains,
9398
customAttributes,
99+
parentTenantId,
94100
}),
95101
(data) => data.tenants,
96102
),

0 commit comments

Comments
 (0)