Skip to content

Commit

Permalink
Merge pull request #204 from CirclesUBI/fix-news-without-ids
Browse files Browse the repository at this point in the history
Return news id in API response
  • Loading branch information
juanenrisley authored Sep 1, 2023
2 parents 40e68bb + 316e902 commit f82a085
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/controllers/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import { Op } from 'sequelize';
import News from '../models/news';
import { respondWithSuccess } from '../helpers/responses';

function prepareNewsResult(response) {
function prepareNewsResult({ dataValues: { message_en, title_en, ...rest } }) {
return {
iconId: response.iconId,
message: {
en: response.message_en,
en: message_en,
},
date: response.date,
isActive: response.isActive,
title: {
en: response.title_en,
en: title_en,
},
...rest,
};
}

Expand Down
18 changes: 18 additions & 0 deletions test/news-find.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ afterAll(async () => {
});

describe('GET /news/?afterDate=... - Search via date', () => {
it('should return the correct response format', () =>
request(app)
.get('/api/news')
.set('Accept', 'application/json')
.expect(httpStatus.OK)
.expect(({ body: { data } }) =>
data.forEach((obj) => {
expect(obj).toHaveProperty('id');
expect(obj).toHaveProperty('date');
expect(obj).toHaveProperty('iconId');
expect(obj).toHaveProperty('isActive');
expect(obj).toHaveProperty('createdAt');
expect(obj).toHaveProperty('updatedAt');
expect(obj).toHaveProperty('title.en');
expect(obj).toHaveProperty('message.en');
}),
));

it('should return active news by default', async () => {
await request(app)
.get('/api/news')
Expand Down

0 comments on commit f82a085

Please sign in to comment.