-
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.
test(api): Update users.contract.ts and add more custom-widgets tests
- Loading branch information
Showing
2 changed files
with
71 additions
and
19 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 |
---|---|---|
|
@@ -127,24 +127,6 @@ describe('Custom Widgets API', () => { | |
}); | ||
|
||
describe('Read API', () => { | ||
it("Shouldn't allow anonymous users to read custom widgets", async () => { | ||
// Given | ||
await entityMocks.createCustomWidget({ | ||
name: 'custom-widget', | ||
user: { id: testUser.id }, | ||
widget: { indicator: baseWidget.indicator }, | ||
}); | ||
|
||
// When | ||
const res = await testManager | ||
.request() | ||
.get(`/users/${VALID_UUID}/widgets`); | ||
|
||
// Then | ||
expect(res.status).toBe(401); | ||
expect(res.body.errors).toBeDefined(); | ||
}); | ||
|
||
it('Should allow authenticated users to read their custom widgets', async () => { | ||
// Given | ||
await entityMocks.createCustomWidget({ | ||
|
@@ -284,6 +266,73 @@ describe('Custom Widgets API', () => { | |
expect(res.status).toBe(403); | ||
expect(res.body.errors).toBeDefined(); | ||
}); | ||
|
||
it("Shouldn't allow authenticated users to read other user's custom widgets by id", async () => { | ||
// Given | ||
// Other user's custom widgets | ||
const { user: otherUser } = await testManager.setUpTestUser({ | ||
email: '[email protected]', | ||
}); | ||
const createdCustomWidget = await entityMocks.createCustomWidget({ | ||
name: 'other-user-custom-widget1', | ||
user: { id: otherUser.id }, | ||
widget: { indicator: baseWidget.indicator }, | ||
}); | ||
|
||
// When | ||
const res = await testManager | ||
.request() | ||
.get(`/users/${otherUser.id}/widgets/${createdCustomWidget.id}`) | ||
.set('Authorization', `Bearer ${authToken}`); | ||
|
||
// Then | ||
expect(res.status).toBe(403); | ||
expect(res.body.errors).toBeDefined(); | ||
}); | ||
|
||
it("Shouldn't allow anonymous users to read other user's custom widgets", async () => { | ||
// Given | ||
// Other user's custom widgets | ||
const { user: otherUser } = await testManager.setUpTestUser({ | ||
email: '[email protected]', | ||
}); | ||
await entityMocks.createCustomWidget({ | ||
name: 'other-user-custom-widget1', | ||
user: { id: otherUser.id }, | ||
widget: { indicator: baseWidget.indicator }, | ||
}); | ||
|
||
// When | ||
const res = await testManager | ||
.request() | ||
.get(`/users/${otherUser.id}/widgets`); | ||
|
||
// Then | ||
expect(res.status).toBe(401); | ||
expect(res.body.errors).toBeDefined(); | ||
}); | ||
|
||
it("Shouldn't allow anonymous users to read other user's custom widgets by id", async () => { | ||
// Given | ||
// Other user's custom widgets | ||
const { user: otherUser } = await testManager.setUpTestUser({ | ||
email: '[email protected]', | ||
}); | ||
const createdCustomWidget = await entityMocks.createCustomWidget({ | ||
name: 'other-user-custom-widget1', | ||
user: { id: otherUser.id }, | ||
widget: { indicator: baseWidget.indicator }, | ||
}); | ||
|
||
// When | ||
const res = await testManager | ||
.request() | ||
.get(`/users/${otherUser.id}/widgets/${createdCustomWidget.id}`); | ||
|
||
// Then | ||
expect(res.status).toBe(401); | ||
expect(res.body.errors).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('Update API', () => { | ||
|
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