Skip to content

Commit 447d40e

Browse files
committed
Add support for check existance of tenant using REST API
1 parent 8d2338b commit 447d40e

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/connection/httpClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ const makeCheckStatus = (expectResponseBody: boolean) => (res: Response) => {
149149
};
150150

151151
const handleHeadResponse = (expectResponseBody: boolean) => (res: Response) => {
152-
if (res.status == 204 || res.status == 404) {
153-
return res.status == 204;
152+
if (res.status == 200 || res.status == 204 || res.status == 404) {
153+
return res.status == 200 || res.status == 204;
154154
}
155155
return makeCheckStatus(expectResponseBody)(res);
156156
};

src/schema/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import TenantsDeleter from './tenantsDeleter';
1414
import Connection from '../connection';
1515
import deleteAll from './deleteAll';
1616
import { Tenant } from '../openapi/types';
17+
import TenantsExists from './tenantsExists';
1718

1819
export interface Schema {
1920
classCreator: () => ClassCreator;
@@ -30,6 +31,7 @@ export interface Schema {
3031
tenantsGetter: (className: string) => TenantsGetter;
3132
tenantsUpdater: (className: string, tenants: Array<Tenant>) => TenantsUpdater;
3233
tenantsDeleter: (className: string, tenants: Array<string>) => TenantsDeleter;
34+
tenantsExists: (className: string, tenant: string) => TenantsExists;
3335
}
3436

3537
const schema = (client: Connection): Schema => {
@@ -51,6 +53,7 @@ const schema = (client: Connection): Schema => {
5153
new TenantsUpdater(client, className, tenants),
5254
tenantsDeleter: (className: string, tenants: Array<string>) =>
5355
new TenantsDeleter(client, className, tenants),
56+
tenantsExists: (className: string, tenant: string) => new TenantsExists(client, className, tenant),
5457
};
5558
};
5659

@@ -66,3 +69,4 @@ export { default as TenantsCreator } from './tenantsCreator';
6669
export { default as TenantsUpdater } from './tenantsUpdater';
6770
export { default as TenantsGetter } from './tenantsGetter';
6871
export { default as TenantsDeleter } from './tenantsDeleter';
72+
export { default as TenantsExists } from './tenantsExists';

src/schema/journey.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,20 @@ describe('multi tenancy', () => {
733733
});
734734
});
735735

736+
it('successfully finds an existing tenant for MultiTenancy class', () => {
737+
return client.schema
738+
.tenantsExists(classObj.class!, tenants[1].name!)
739+
.do()
740+
.then((res: boolean) => expect(res).toEqual(true));
741+
});
742+
743+
it('successfully fails to find a non-existant tenant for MultiTenancy class', () => {
744+
return client.schema
745+
.tenantsExists(classObj.class!, 'nonExistantTenant')
746+
.do()
747+
.then((res: boolean) => expect(res).toEqual(false));
748+
});
749+
736750
it('deletes MultiTenancy class', () => {
737751
return deleteClass(client, classObj.class!);
738752
});

src/schema/tenantsExists.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Connection from '../connection';
2+
import { CommandBase } from '../validation/commandBase';
3+
import { Tenant } from '../openapi/types';
4+
5+
export default class TenantsExists extends CommandBase {
6+
private className: string;
7+
private tenant: string;
8+
9+
constructor(client: Connection, className: string, tenant: string) {
10+
super(client);
11+
this.className = className;
12+
this.tenant = tenant;
13+
}
14+
15+
validate = () => {
16+
// nothing to validate
17+
};
18+
19+
do = (): Promise<boolean> => {
20+
return this.client.head(`/schema/${this.className}/tenants/${this.tenant}`, undefined);
21+
};
22+
}

0 commit comments

Comments
 (0)