|
1 | | -import weaviate, { ApiKey, Permission, Role, WeaviateClient } from '..'; |
| 1 | +import weaviate, { ApiKey, Permission, Role, UserAssignment, WeaviateClient } from '..'; |
| 2 | +import { requireAtLeast } from '../../test/version'; |
2 | 3 | import { WeaviateStartUpError, WeaviateUnexpectedStatusCodeError } from '../errors'; |
3 | | -import { DbVersion } from '../utils/dbVersion'; |
4 | 4 |
|
5 | | -const only = DbVersion.fromString(`v${process.env.WEAVIATE_VERSION!}`).isAtLeast(1, 29, 0) |
6 | | - ? describe |
7 | | - : describe.skip; |
8 | | - |
9 | | -only('Integration testing of the roles namespace', () => { |
| 5 | +requireAtLeast( |
| 6 | + 1, |
| 7 | + 29, |
| 8 | + 0 |
| 9 | +)('Integration testing of the roles namespace', () => { |
10 | 10 | let client: WeaviateClient; |
11 | 11 |
|
12 | 12 | beforeAll(async () => { |
@@ -40,6 +40,35 @@ only('Integration testing of the roles namespace', () => { |
40 | 40 | expect(exists).toBeFalsy(); |
41 | 41 | }); |
42 | 42 |
|
| 43 | + requireAtLeast( |
| 44 | + 1, |
| 45 | + 30, |
| 46 | + 0 |
| 47 | + )('namespaced users', () => { |
| 48 | + it('retrieves assigned users with namespace', async () => { |
| 49 | + await client.roles.create('landlord', { |
| 50 | + collection: 'Buildings', |
| 51 | + actions: ['create_tenants', 'delete_tenants'], |
| 52 | + }); |
| 53 | + |
| 54 | + await client.users.db.create('Innkeeper').catch((res) => expect(res.code).toEqual(409)); |
| 55 | + |
| 56 | + await client.users.db.assignRoles('landlord', 'custom-user'); |
| 57 | + await client.users.db.assignRoles('landlord', 'Innkeeper'); |
| 58 | + |
| 59 | + const assignments = await client.roles.userAssignments('landlord'); |
| 60 | + |
| 61 | + expect(assignments).toEqual( |
| 62 | + expect.arrayContaining([ |
| 63 | + expect.objectContaining<UserAssignment>({ id: 'custom-user', userType: 'db_env_user' }), |
| 64 | + expect.objectContaining<UserAssignment>({ id: 'Innkeeper', userType: 'db_user' }), |
| 65 | + ]) |
| 66 | + ); |
| 67 | + |
| 68 | + await client.users.db.delete('Innkeeper'); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
43 | 72 | describe('should be able to create roles using the permissions factory', () => { |
44 | 73 | type TestCase = { |
45 | 74 | roleName: string; |
@@ -262,6 +291,7 @@ only('Integration testing of the roles namespace', () => { |
262 | 291 | 'roles', |
263 | 292 | 'tenants', |
264 | 293 | 'users', |
| 294 | + 'landlord', |
265 | 295 | ].map((n) => client.roles.delete(n)) |
266 | 296 | ) |
267 | 297 | ); |
|
0 commit comments