-
-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
133 additions
and
42 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init'; | ||
import getLogger from '../../../test/fixtures/no-logger'; | ||
import { type IUser, RoleName } from '../../types'; | ||
import { type IUser, RoleName, type IGroup } from '../../types'; | ||
import { randomId } from '../../util'; | ||
import { ProjectOwnersReadModel } from './project-owners-read-model'; | ||
|
||
|
@@ -14,21 +14,24 @@ describe('unit tests', () => { | |
let db: ITestDb; | ||
let readModel: ProjectOwnersReadModel; | ||
|
||
let ownerRoleId: number; | ||
let owner: IUser; | ||
let member: IUser; | ||
let group: IGroup; | ||
|
||
beforeAll(async () => { | ||
db = await dbInit('project_owners_read_model_serial', getLogger); | ||
readModel = new ProjectOwnersReadModel(db.rawDatabase, db.stores.roleStore); | ||
ownerRoleId = (await db.stores.roleStore.getRoleByName(RoleName.OWNER)).id; | ||
|
||
const ownerData = { | ||
name: 'owner', | ||
name: 'Owner User', | ||
username: 'owner', | ||
email: '[email protected]', | ||
imageUrl: 'image-url-1', | ||
}; | ||
const memberData = { | ||
name: 'member', | ||
name: 'Member Name', | ||
username: 'member', | ||
email: '[email protected]', | ||
imageUrl: 'image-url-2', | ||
|
@@ -37,6 +40,10 @@ beforeAll(async () => { | |
// create users | ||
owner = await db.stores.userStore.insert(ownerData); | ||
member = await db.stores.userStore.insert(memberData); | ||
|
||
// create groups | ||
group = await db.stores.groupStore.create({ name: 'Group Name' }); | ||
await db.stores.groupStore.addUserToGroups(owner.id, [group.id]); | ||
}); | ||
|
||
afterAll(async () => { | ||
|
@@ -57,35 +64,51 @@ afterEach(async () => { | |
}); | ||
|
||
describe('integration tests', () => { | ||
test('name takes precedence over username', () => { | ||
// import { extractUsername } from '../../../util/extract-user'; | ||
test('name takes precedence over username', async () => { | ||
const projectId = randomId(); | ||
await db.stores.projectStore.create({ id: projectId, name: projectId }); | ||
|
||
await db.stores.accessStore.addUserToRole( | ||
owner.id, | ||
ownerRoleId, | ||
projectId, | ||
); | ||
|
||
const owners = await readModel.getAllProjectOwners(); | ||
expect(owners).toMatchObject({ | ||
[projectId]: expect.arrayContaining([ | ||
expect.objectContaining({ name: 'Owner User' }), | ||
]), | ||
}); | ||
}); | ||
|
||
test('gets project user owners', async () => { | ||
const projectId = randomId(); | ||
|
||
await db.stores.projectStore.create({ id: projectId, name: projectId }); | ||
|
||
const ownerRole = await db.stores.roleStore.getRoleByName( | ||
RoleName.OWNER, | ||
); | ||
await db.stores.accessStore.addUserToRole( | ||
owner.id, | ||
ownerRole.id, | ||
ownerRoleId, | ||
projectId, | ||
); | ||
|
||
// fetch project owners | ||
const owners = await readModel.getAllProjectOwners(); | ||
|
||
expect(owners).toMatchObject({ | ||
[projectId]: [{ name: 'owner' }], | ||
[projectId]: [ | ||
{ | ||
ownerType: 'user', | ||
name: 'Owner User', | ||
email: '[email protected]', | ||
imageUrl: 'image-url-1', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('does not get regular project members', async () => { | ||
const projectId = randomId(); | ||
|
||
await db.stores.projectStore.create({ id: projectId, name: projectId }); | ||
|
||
const ownerRole = await db.stores.roleStore.getRoleByName( | ||
|
@@ -97,7 +120,7 @@ describe('integration tests', () => { | |
); | ||
await db.stores.accessStore.addUserToRole( | ||
owner.id, | ||
ownerRole.id, | ||
ownerRoleId, | ||
projectId, | ||
); | ||
|
||
|
@@ -111,14 +134,40 @@ describe('integration tests', () => { | |
const owners = await readModel.getAllProjectOwners(); | ||
|
||
expect(owners).toMatchObject({ | ||
[projectId]: [{ name: 'owner' }], | ||
[projectId]: [{ name: 'Owner User' }], | ||
}); | ||
}); | ||
|
||
test('gets project group owners', async () => { | ||
const projectId = randomId(); | ||
await db.stores.projectStore.create({ id: projectId, name: projectId }); | ||
|
||
await db.stores.accessStore.addGroupToRole( | ||
group.id, | ||
ownerRoleId, | ||
'', | ||
projectId, | ||
); | ||
|
||
// fetch project owners | ||
const owners = await readModel.getAllProjectOwners(); | ||
|
||
expect(owners).toMatchObject({ | ||
[projectId]: [ | ||
{ | ||
ownerType: 'group', | ||
name: 'Group Name', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('gets project group owners', async () => {}); | ||
test('users are listed before groups', async () => {}); | ||
|
||
test('owners (users and groups) are sorted by when they were added; oldest first', async () => {}); | ||
test('returns the system owner for the default project', () => {}); | ||
|
||
test('returns the system owner for the default project', async () => {}); | ||
|
||
test('returns an empty list if there are no projects', async () => { | ||
const owners = await readModel.getAllProjectOwners(); | ||
|
||
|
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