Skip to content

Commit

Permalink
feat(api): Return custom-widget along with the related base-widget an…
Browse files Browse the repository at this point in the history
…d improve custom-widget tests
  • Loading branch information
alepefe committed Nov 8, 2024
1 parent e09cc65 commit 6175a9a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
9 changes: 6 additions & 3 deletions api/src/modules/widgets/custom-widgets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ export class CustomWidgetService extends AppBaseService<
throw new ForbiddenException();
}

const customWidget = await this.customWidgetRepository.findOneBy({
id,
user: { id: userId },
const customWidget = await this.customWidgetRepository.findOne({
where: {
id,
user: { id: userId },
},
relations: ['widget'],
});

if (customWidget === null) {
Expand Down
31 changes: 20 additions & 11 deletions api/test/e2e/users/custom-widgets/custom-widget-crud.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,18 @@ describe('Custom Widgets API', () => {

it('Should allow authenticated users to read their custom widgets', async () => {
// Given
await entityMocks.createCustomWidget({
name: 'custom-widget1',
user: { id: testUser.id },
widget: { indicator: baseWidget.indicator },
});
await entityMocks.createCustomWidget({
name: 'custom-widget2',
user: { id: testUser.id },
widget: { indicator: baseWidget.indicator },
});
const userCustomWidgets = [
await entityMocks.createCustomWidget({
name: 'custom-widget1',
user: { id: testUser.id },
widget: { indicator: baseWidget.indicator },
}),
await entityMocks.createCustomWidget({
name: 'custom-widget2',
user: { id: testUser.id },
widget: { indicator: baseWidget.indicator },
}),
];

// Other user's custom widgets
const { user: otherUser } = await testManager.setUpTestUser({
Expand All @@ -198,7 +200,14 @@ describe('Custom Widgets API', () => {

// Then
expect(res.status).toBe(200);
expect(res.body.data).toHaveLength(2);
const returnedData = res.body.data;
expect(returnedData).toHaveLength(2);
for (const userCustomWidget of userCustomWidgets) {
const foundWidget = returnedData.find(
(r) => r.name === userCustomWidget.name,
);
expect(foundWidget).toBeDefined();
}
});

// TODO: Skipping this tests as filtering capabilities are not working, pending to fix the corresponding schema
Expand Down

0 comments on commit 6175a9a

Please sign in to comment.