Skip to content

Commit adcc5f1

Browse files
tests: multi-tanent test fixes
1 parent 9d7e744 commit adcc5f1

25 files changed

+103
-22
lines changed

src/authorization/graphql/entity.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type Entity {
22
id: ID!
33
name: String!
4+
tenantId: String!
45
permissions: [Permission]
56
}
67

src/authorization/graphql/group.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type Group {
22
id: ID!
33
name: String!
4+
tenantId: String!
45
users: [User]
56
roles: [Role]
67
permissions: [Permission]
@@ -27,6 +28,7 @@ input UpdateGroupRoleInput {
2728
type GroupRole {
2829
id: ID!,
2930
name: String!
31+
tenantId: String!
3032
}
3133

3234
input GroupInputFilter {

src/authorization/graphql/role.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type Role {
22
id: ID!
33
name: String!
4+
tenantId: String!
45
permissions: [Permission]
56
}
67

src/authorization/graphql/user.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type User {
2020
groups: [Group]
2121
permissions: [Permission]
2222
inviteToken: String
23+
tenantId: String!
2324
}
2425

2526
enum OperationType {
@@ -44,6 +45,7 @@ input UpdateUserGroupInput {
4445
type UserGroupResponse {
4546
id: ID!,
4647
name: String!
48+
tenantId: String!
4749
}
4850

4951
enum OperationType {

src/schema/graphql.schema.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ export interface InviteTokenResponse {
291291
export interface Entity {
292292
id: string;
293293
name: string;
294+
tenantId: string;
294295
permissions?: Permission[];
295296
}
296297

@@ -318,6 +319,7 @@ export interface IQuery {
318319
export interface Group {
319320
id: string;
320321
name: string;
322+
tenantId: string;
321323
users?: User[];
322324
roles?: Role[];
323325
permissions?: Permission[];
@@ -327,6 +329,7 @@ export interface Group {
327329
export interface GroupRole {
328330
id: string;
329331
name: string;
332+
tenantId: string;
330333
}
331334

332335
export interface GroupPaginated extends Paginated {
@@ -343,6 +346,7 @@ export interface Permission {
343346
export interface Role {
344347
id: string;
345348
name: string;
349+
tenantId: string;
346350
permissions?: Permission[];
347351
}
348352

@@ -367,9 +371,11 @@ export interface User {
367371
groups?: Group[];
368372
permissions?: Permission[];
369373
inviteToken?: string;
374+
tenantId: string;
370375
}
371376

372377
export interface UserGroupResponse {
373378
id: string;
374379
name: string;
380+
tenantId: string;
375381
}

test/authentication/resolver/userauth.resolver.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const users: User[] = [
3535
lastName: 'User',
3636
origin: 'simple',
3737
status: Status.ACTIVE,
38+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
3839
},
3940
];
4041

@@ -94,6 +95,7 @@ describe('Userauth Module', () => {
9495
firstName: users[0].firstName,
9596
lastName: users[0].lastName,
9697
status: users[0].status,
98+
tenantId: users[0].tenantId,
9799
};
98100
const tokenResponse = {
99101
accessToken: `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
@@ -114,7 +116,7 @@ describe('Userauth Module', () => {
114116
.post(gql)
115117
.send({
116118
query:
117-
'mutation { passwordLogin(input: { username: "user@test.com" password: "s3cr3t1234567890" }) { accessToken, refreshToken, user{ id, email, phone, firstName, lastName, status } }}',
119+
'mutation { passwordLogin(input: { username: "user@test.com" password: "s3cr3t1234567890" }) { accessToken, refreshToken, user{ id, email, phone, firstName, lastName, status tenantId} }}',
118120
})
119121
.expect(200)
120122
.expect((res) => {
@@ -184,6 +186,7 @@ describe('Userauth Module', () => {
184186
inviteToken:
185187
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Inh5ekBrZXl2YWx1ZS5zeXN0ZW1zIiwiaWF0IjoxNjIxNTI1NTE1LCJleHAiOjE2MjE1MjkxMTV9.t8z7rBZKkog-1jirScYU6HE7KVTzatKWjZw8lVz3xLo',
186188
status: Status.INVITED,
189+
tenantId: users[0].tenantId,
187190
},
188191
};
189192
configService.get('JWT_SECRET').returns('s3cr3t1234567890');
@@ -199,7 +202,7 @@ describe('Userauth Module', () => {
199202
.set('Authorization', `Bearer ${token}`)
200203
.send({
201204
query: `mutation { inviteTokenSignup(input: { email: "test@gmail.com"
202-
phone: "9947849200" firstName: "Test" lastName: "Name" }) { inviteToken tokenExpiryTime user{id firstName lastName inviteToken status}}}`,
205+
phone: "9947849200" firstName: "Test" lastName: "Name" }) { inviteToken tokenExpiryTime user{id firstName lastName inviteToken status tenantId}}}`,
203206
})
204207
.expect(200)
205208
.expect((res) => {
@@ -283,6 +286,7 @@ describe('Userauth Module', () => {
283286
inviteToken:
284287
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Inh5ekBrZXl2YWx1ZS5zeXN0ZW1zIiwiaWF0IjoxNjIxNTI1NTE1LCJleHAiOjE2MjE1MjkxMTV9.t8z7rBZKkog-1jirScYU6HE7KVTzatKWjZw8lVz3xLo',
285288
status: Status.INVITED,
289+
tenantId: users[0].tenantId,
286290
},
287291
};
288292
tokenService
@@ -303,6 +307,7 @@ describe('Userauth Module', () => {
303307
lastName
304308
inviteToken
305309
status
310+
tenantId
306311
}
307312
}
308313
}`,
@@ -340,6 +345,7 @@ describe('Userauth Module', () => {
340345
firstName: users[0].firstName,
341346
lastName: users[0].lastName,
342347
status: users[0].status,
348+
tenantId: users[0].tenantId,
343349
};
344350
const tokenResponse: TokenResponse = { ...token, user: user };
345351
tokenService
@@ -349,7 +355,7 @@ describe('Userauth Module', () => {
349355
return request(app.getHttpServer())
350356
.post(gql)
351357
.send({
352-
query: `mutation { refresh(input: { refreshToken: "${token.refreshToken}"}) { accessToken refreshToken user { id, email, phone, firstName, lastName, status} }}`,
358+
query: `mutation { refresh(input: { refreshToken: "${token.refreshToken}"}) { accessToken refreshToken user { id, email, phone, firstName, lastName, status tenantId} }}`,
353359
})
354360
.expect(200)
355361
.expect((res) => {

test/authentication/service/otpauth.service.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ let users: User[] = [
2828
lastName: 'Test2',
2929
origin: 'simple',
3030
status: Status.ACTIVE,
31+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
3132
},
3233
];
3334

@@ -72,6 +73,7 @@ describe('test OTPAuthService', () => {
7273
refreshToken: token.refreshToken,
7374
origin: 'simple',
7475
status: Status.ACTIVE,
76+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
7577
},
7678
];
7779
});
@@ -88,6 +90,7 @@ describe('test OTPAuthService', () => {
8890
lastName: 'Test2',
8991
origin: 'simple',
9092
status: Status.ACTIVE,
93+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
9194
},
9295
];
9396

@@ -126,6 +129,7 @@ describe('test OTPAuthService', () => {
126129
lastName: 'Test2',
127130
origin: 'simple',
128131
status: Status.ACTIVE,
132+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
129133
},
130134
];
131135
const input: UserOTPLoginInput = {
@@ -152,6 +156,7 @@ describe('test OTPAuthService', () => {
152156
lastName: users[0].lastName,
153157
origin: 'simple',
154158
status: Status.ACTIVE,
159+
tenantId: users[0].tenantId,
155160
},
156161
];
157162
const userSignup: UserOTPSignupInput = {
@@ -179,6 +184,7 @@ describe('test OTPAuthService', () => {
179184
lastName: resp.lastName,
180185
origin: 'simple',
181186
status: Status.ACTIVE,
187+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
182188
};
183189

184190
const expectedUser = users[0];
@@ -195,6 +201,7 @@ describe('test OTPAuthService', () => {
195201
lastName: 'Test2',
196202
origin: 'simple',
197203
status: Status.ACTIVE,
204+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
198205
},
199206
];
200207
const userSignup: UserOTPSignupInput = {

test/authentication/service/passwordauth.service.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let users: User[] = [
1919
lastName: 'Test2',
2020
origin: 'simple',
2121
status: Status.ACTIVE,
22+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
2223
},
2324
];
2425

@@ -74,6 +75,7 @@ describe('test PasswordAuthService', () => {
7475
refreshToken: token.refreshToken,
7576
origin: 'simple',
7677
status: Status.ACTIVE,
78+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
7779
},
7880
];
7981
});

test/authentication/service/token.service.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('test TokenService', () => {
4747
lastName: 'Test2',
4848
origin: 'simple',
4949
status: Status.ACTIVE,
50+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
5051
},
5152
];
5253
const token = authenticationHelper.generateTokenForUser(users[0]);
@@ -71,6 +72,7 @@ describe('test TokenService', () => {
7172
lastName: 'Test2',
7273
origin: 'simple',
7374
status: Status.ACTIVE,
75+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
7476
},
7577
];
7678
const refreshInviteToken = authenticationHelper.generateInvitationToken(
@@ -103,6 +105,7 @@ describe('test TokenService', () => {
103105
lastName: 'Test2',
104106
origin: 'simple',
105107
status: Status.ACTIVE,
108+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
106109
},
107110
];
108111
userService
@@ -125,6 +128,7 @@ describe('test TokenService', () => {
125128
lastName: 'Test2',
126129
origin: 'simple',
127130
status: Status.ACTIVE,
131+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
128132
},
129133
];
130134
userService
@@ -144,6 +148,7 @@ describe('test TokenService', () => {
144148
lastName: 'Test2',
145149
origin: 'simple',
146150
status: Status.ACTIVE,
151+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
147152
},
148153
];
149154
users[0].inviteToken = '';

test/authorization/repository/entity.repository.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const VALID_ENTITY_ID = 'ae032b1b-cc3c-4e44-9197-276ca877a7f8';
88
const entity: Entity = {
99
id: VALID_ENTITY_ID,
1010
name: 'Test Entity 1',
11+
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
1112
};
1213

1314
const updateResult: UpdateResult = {

0 commit comments

Comments
 (0)