Skip to content

Commit f06dfc6

Browse files
fix(tasks): address review — org-scoped stats assertion, fresh agent for logout, fix markdown
1 parent 3681804 commit f06dfc6

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

MIGRATIONS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Rate-limit middleware now keys authenticated requests by `user._id` (with `req.i
3232
- `modules/tasks/repositories/tasks.repository.js``stats()` uses `countDocuments(filter)` instead of `estimatedDocumentCount()`
3333

3434
### Action for downstream
35-
3635
1. Any unauthenticated call to `/api/tasks/stats` will now return `401`
3736
2. Authenticated calls return the count scoped to the user's current organization
3837
3. Run `/update-stack` to pull the change

modules/tasks/tests/tasks.integration.tests.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('Tasks integration tests:', () => {
1717
const originalOrgEnabled = config.organizations.enabled;
1818
let TasksService;
1919
let TasksDataService;
20+
let app; // Express app instance for fresh (unauthenticated) requests
2021
let agent;
2122
let user;
2223
let _user;
@@ -33,7 +34,8 @@ describe('Tasks integration tests:', () => {
3334
UserService = (await import(path.resolve('./modules/users/services/users.service.js'))).default;
3435
TasksService = (await import(path.resolve('./modules/tasks/services/tasks.service.js'))).default;
3536
TasksDataService = (await import(path.resolve('./modules/tasks/services/tasks.data.service.js'))).default;
36-
agent = request.agent(init.app);
37+
app = init.app;
38+
agent = request.agent(app);
3739
} catch (err) {
3840
console.log(err);
3941
expect(err).toBeFalsy();
@@ -253,12 +255,18 @@ describe('Tasks integration tests:', () => {
253255
}
254256
});
255257

256-
test('should be able to get tasks stats when authenticated', async () => {
258+
test('should be able to get tasks stats when authenticated (org-scoped)', async () => {
257259
try {
260+
const tasksResult = await agent.get('/api/tasks').expect(200);
261+
expect(tasksResult.body.type).toBe('success');
262+
expect(tasksResult.body.message).toBe('task list');
263+
expect(tasksResult.body.data).toBeInstanceOf(Array);
264+
258265
const result = await agent.get('/api/tasks/stats').expect(200);
259266
expect(result.body.type).toBe('success');
260267
expect(result.body.message).toBe('tasks stats');
261268
expect(typeof result.body.data).toBe('number');
269+
expect(result.body.data).toBe(tasksResult.body.data.length);
262270
} catch (err) {
263271
console.log(err);
264272
expect(err).toBeFalsy();
@@ -285,7 +293,7 @@ describe('Tasks integration tests:', () => {
285293
describe('Logout', () => {
286294
test('should not be able to save a task', async () => {
287295
try {
288-
const result = await agent.post('/api/tasks').send(_tasks[0]).expect(401);
296+
const result = await request(app).post('/api/tasks').send(_tasks[0]).expect(401);
289297
expect(result.error.text).toBe('Unauthorized');
290298
} catch (err) {
291299
expect(err).toBeFalsy();
@@ -294,9 +302,8 @@ describe('Tasks integration tests:', () => {
294302
});
295303

296304
test('should not be able to get list of tasks without auth', async () => {
297-
// task list now requires authentication
298305
try {
299-
await agent.get('/api/tasks').expect(401);
306+
await request(app).get('/api/tasks').expect(401);
300307
} catch (err) {
301308
console.log(err);
302309
expect(err).toBeFalsy();
@@ -305,7 +312,7 @@ describe('Tasks integration tests:', () => {
305312

306313
test('should not be able to get tasks stats without auth', async () => {
307314
try {
308-
await agent.get('/api/tasks/stats').expect(401);
315+
await request(app).get('/api/tasks/stats').expect(401);
309316
} catch (err) {
310317
expect(err).toBeFalsy();
311318
console.log(err);

0 commit comments

Comments
 (0)