5. You want to test an Express GET endpoint that returns a list of users, but only those with active status true. Which test code correctly checks this filtering?
app.get('/active-users', (req, res) => {
const users = [
{ id: 1, active: true },
{ id: 2, active: false },
{ id: 3, active: true }
];
res.json(users.filter(u => u.active));
});
// Test code options:
A) await request(app).get('/active-users').expect(200).expect(res => {
if (!res.body.every(u => u.active)) throw new Error('Inactive user found');
});
B) await request(app).get('/active-users').expect(200).expect(res => {
if (res.body.length !== 3) throw new Error('Wrong number of users');
});
C) await request(app).get('/active-users').expect(404);
D) await request(app).get('/active-users').expect(200).expect(res => {
if (!res.body.some(u => u.active === false)) throw new Error('Inactive user found');
});