-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(syncs): show syncs a user can see
based on their project membership
- Loading branch information
1 parent
9b91488
commit 057036b
Showing
6 changed files
with
187 additions
and
38 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
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
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
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
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
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 |
---|---|---|
|
@@ -183,23 +183,91 @@ describe('sync', async () => { | |
}) | ||
}) | ||
|
||
it('should list syncs', async () => { | ||
const { syncs } = (await listSyncs(dbContext)(user)) as { | ||
syncs: SerializedSync[] | ||
} | ||
describe('list syncs', () => { | ||
it('should list syncs owned by the user', async () => { | ||
const { syncs } = (await listSyncs(dbContext)(user)) as { | ||
syncs: SerializedSync[] | ||
} | ||
|
||
check(syncs?.[0]).is( | ||
objectMatching({ | ||
id: aString, | ||
title: 'My sync', | ||
owner: user.sub, | ||
}), | ||
) | ||
check(syncs?.[0]?.projectIds.sort((a, b) => a.localeCompare(b))).is( | ||
arrayMatching( | ||
[projectA, projectB].sort((a, b) => a.localeCompare(b)).map(l), | ||
), | ||
) | ||
check(syncs?.[0]).is( | ||
objectMatching({ | ||
id: aString, | ||
title: 'My sync', | ||
owner: user.sub, | ||
}), | ||
) | ||
check(syncs?.[0]?.projectIds.sort((a, b) => a.localeCompare(b))).is( | ||
arrayMatching( | ||
[projectA, projectB].sort((a, b) => a.localeCompare(b)).map(l), | ||
), | ||
) | ||
}) | ||
|
||
it('should list syncs that the user has access to', async () => { | ||
const organizationId = `$test-user-sync-${ulid()}` | ||
const projectA = `${organizationId}#test-${ulid()}` | ||
const projectB = `${organizationId}#test-${ulid()}` | ||
const projectC = `${organizationId}#test-${ulid()}` | ||
const projectIds = [projectA, projectB, projectC] | ||
|
||
// This user will be invited to the projects as a member and should see the syncs | ||
const jo: UserAuthContext = { | ||
email: '[email protected]', | ||
sub: '@jo', | ||
} | ||
|
||
// Create the organization | ||
isNotAnError( | ||
await createOrganization(dbContext, notify)( | ||
{ | ||
id: organizationId, | ||
name: `Organization ${organizationId}`, | ||
}, | ||
user, | ||
), | ||
) | ||
|
||
// Create the projects | ||
const syncIds: string[] = [] | ||
for (const projectId of projectIds) { | ||
// Create the project | ||
isNotAnError( | ||
await createProject(dbContext, notify)( | ||
{ | ||
id: projectId, | ||
name: `Project ${projectId}`, | ||
}, | ||
user, | ||
), | ||
) | ||
// Create a sync | ||
const id = ulid() | ||
syncIds.push(id) | ||
isNotAnError( | ||
await createSync(dbContext, notify)( | ||
{ | ||
id, | ||
projectIds: new Set([projectId]), | ||
}, | ||
user, | ||
), | ||
) | ||
// Create a member | ||
await createProjectMember(dbContext, notify)( | ||
projectId, | ||
jo.sub, | ||
Role.WATCHER, | ||
) | ||
} | ||
eventually(async () => { | ||
const { syncs } = (await listSyncs(dbContext)(jo)) as { | ||
syncs: SerializedSync[] | ||
} | ||
for (const syncId of syncIds) { | ||
check(syncs).is(arrayContaining(objectMatching({ id: syncId }))) | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
describe('accessing syncs', async () => { | ||
|