532 lines
21 KiB
TypeScript
532 lines
21 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { prisma } from '../../src/lib/prisma.js';
|
|
import {
|
|
buildAgent,
|
|
buildApp,
|
|
createExercise,
|
|
createUser,
|
|
createUserWithToken,
|
|
loginViaApi,
|
|
rand,
|
|
registerViaApi,
|
|
seedPlan,
|
|
seedSession,
|
|
createMembership,
|
|
} from '../helpers.js';
|
|
|
|
// Data startu musi być z bieżącego lub przyszłego tygodnia — dynamiczny poniedziałek.
|
|
function mondayIso(offsetWeeks: number): string {
|
|
const d = new Date();
|
|
d.setDate(d.getDate() - ((d.getDay() + 6) % 7) + offsetWeeks * 7);
|
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
}
|
|
const MONDAY = mondayIso(1);
|
|
|
|
/** Poniedziałek startu + N dni (YYYY-MM-DD) — cel przesunięcia dnia treningowego. */
|
|
function mondayPlus(days: number): string {
|
|
const [y, m, d] = MONDAY.split('-').map(Number);
|
|
const dt = new Date(y, m - 1, d + days);
|
|
return `${dt.getFullYear()}-${String(dt.getMonth() + 1).padStart(2, '0')}-${String(dt.getDate()).padStart(2, '0')}`;
|
|
}
|
|
|
|
describe('activity logs (audit trail)', () => {
|
|
it('rejects GET /admin/logs without auth with 401', async () => {
|
|
const res = await buildApp().get('/api/v1/admin/logs');
|
|
expect(res.status).toBe(401);
|
|
});
|
|
|
|
it('rejects GET /admin/logs for a non-admin user with 403', async () => {
|
|
const { token } = await registerViaApi();
|
|
const res = await buildApp().get('/api/v1/admin/logs').set('Authorization', `Bearer ${token}`);
|
|
expect(res.status).toBe(403);
|
|
});
|
|
|
|
it('records user registration', async () => {
|
|
const { user } = await registerViaApi();
|
|
const log = await prisma.activityLog.findFirst({
|
|
where: { actorId: user.id, action: 'user.registered' },
|
|
});
|
|
expect(log).toBeTruthy();
|
|
expect(log?.entityType).toBe('user');
|
|
expect(log?.entityId).toBe(user.id);
|
|
expect(log?.details).toMatchObject({ actorId: user.id, email: user.email });
|
|
});
|
|
|
|
it('records the plan lifecycle (created, activated, day moved, abandoned)', async () => {
|
|
const { token, user } = await registerViaApi();
|
|
const exercise = await createExercise();
|
|
const app = buildApp();
|
|
const created = await app
|
|
.post('/api/v1/plans')
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.send({
|
|
title: 'Audit plan',
|
|
weeksCount: 1,
|
|
weeks: [
|
|
{
|
|
index: 0,
|
|
days: [
|
|
{
|
|
dayOfWeek: 1,
|
|
exercises: [{ exerciseId: exercise.id, order: 0, sets: [{ index: 0, reps: 10 }] }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
expect(created.status).toBe(201);
|
|
const planId = created.body.plan.id;
|
|
|
|
const activated = await app
|
|
.post(`/api/v1/plans/${planId}/activate`)
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.send({ startDate: MONDAY });
|
|
expect(activated.status).toBe(200);
|
|
|
|
const detail = await app
|
|
.get(`/api/v1/plans/${planId}`)
|
|
.set('Authorization', `Bearer ${token}`);
|
|
const dayId = detail.body.plan.weeks[0].days[0].id;
|
|
const moved = await app
|
|
.patch(`/api/v1/plans/${planId}/days/${dayId}/move`)
|
|
.set('Authorization', `Bearer ${token}`)
|
|
.send({ date: mondayPlus(2), reason: 'kontuzja' });
|
|
expect(moved.status).toBe(200);
|
|
|
|
const abandoned = await app
|
|
.post(`/api/v1/plans/${planId}/abandon`)
|
|
.set('Authorization', `Bearer ${token}`);
|
|
expect(abandoned.status).toBe(200);
|
|
|
|
const logs = await prisma.activityLog.findMany({
|
|
where: { actorId: user.id, entityType: 'plan' },
|
|
orderBy: { createdAt: 'asc' },
|
|
});
|
|
expect(logs.map((l) => l.action)).toEqual([
|
|
'plan.created',
|
|
'plan.activated',
|
|
'plan.day.moved',
|
|
'plan.abandoned',
|
|
]);
|
|
expect(logs[0].details).toMatchObject({ actorId: user.id, title: 'Audit plan' });
|
|
expect(logs[1].details).toMatchObject({
|
|
actorId: user.id,
|
|
title: 'Audit plan',
|
|
startDate: MONDAY,
|
|
});
|
|
expect(logs[2].details).toMatchObject({ actorId: user.id, dayId, reason: 'kontuzja' });
|
|
expect(logs[3].entityId).toBe(planId);
|
|
});
|
|
|
|
it('records session lifecycle with plan context in details (started, completed, reopened, abandoned)', async () => {
|
|
const { token, user } = await registerViaApi();
|
|
const plan = await seedPlan({
|
|
userId: user.id,
|
|
title: 'Audit sessions plan',
|
|
status: 'ACTIVE',
|
|
startDate: new Date(MONDAY),
|
|
weeks: [{ index: 0, days: [{ dayOfWeek: 1, date: new Date(MONDAY) }] }],
|
|
});
|
|
const dayId = plan.weeks[0].days[0].id;
|
|
const app = buildApp();
|
|
const auth = { Authorization: `Bearer ${token}` };
|
|
|
|
const started = await app.post(`/api/v1/days/${dayId}/sessions`).set(auth);
|
|
expect(started.status).toBe(201);
|
|
const sessionId = started.body.sessionId;
|
|
|
|
const completed = await app.post(`/api/v1/sessions/${sessionId}/complete`).set(auth);
|
|
expect(completed.status).toBe(200);
|
|
|
|
const reopened = await app.post(`/api/v1/sessions/${sessionId}/reopen`).set(auth);
|
|
expect(reopened.status).toBe(200);
|
|
|
|
const abandoned = await app.post(`/api/v1/sessions/${sessionId}/abandon`).set(auth);
|
|
expect(abandoned.status).toBe(200);
|
|
|
|
const logs = await prisma.activityLog.findMany({
|
|
where: { actorId: user.id, entityType: 'session' },
|
|
orderBy: { createdAt: 'asc' },
|
|
});
|
|
expect(logs.map((l) => l.action)).toEqual([
|
|
'session.started',
|
|
'session.completed',
|
|
'session.reopened',
|
|
'session.abandoned',
|
|
]);
|
|
expect(logs.map((l) => l.entityId)).toEqual([sessionId, sessionId, sessionId, sessionId]);
|
|
// details zawsze zawiera ID aktora + snapshot kontekstu (dzień, plan, tytuł planu)
|
|
const context = { actorId: user.id, dayId, planId: plan.id, planTitle: 'Audit sessions plan' };
|
|
for (const log of logs) expect(log.details).toMatchObject(context);
|
|
// przy ukończeniu dodatkowo liczniki z podsumowania (plan bez ćwiczeń = zera)
|
|
expect(logs[1].details).toMatchObject({ ...context, exercises: 0, sets: 0 });
|
|
});
|
|
|
|
it('records body parameter removal', async () => {
|
|
const { token, user } = await registerViaApi();
|
|
const app = buildApp();
|
|
const auth = { Authorization: `Bearer ${token}` };
|
|
|
|
const weight = await app
|
|
.post('/api/v1/me/body-parameters/weight')
|
|
.set(auth)
|
|
.send({ value: 82.5 });
|
|
const circ = await app
|
|
.post('/api/v1/me/body-parameters/circumference')
|
|
.set(auth)
|
|
.send({ typeId: 'biceps', value: 40 });
|
|
expect(
|
|
(await app.delete(`/api/v1/me/body-parameters/weight/${weight.body.id}`).set(auth)).status,
|
|
).toBe(204);
|
|
expect(
|
|
(await app.delete(`/api/v1/me/body-parameters/circumference/${circ.body.id}`).set(auth))
|
|
.status,
|
|
).toBe(204);
|
|
|
|
const logs = await prisma.activityLog.findMany({
|
|
where: { actorId: user.id, action: { in: ['weight.removed', 'circumference.removed'] } },
|
|
});
|
|
expect(logs).toHaveLength(2);
|
|
expect(logs.find((l) => l.action === 'weight.removed')?.details).toMatchObject({
|
|
actorId: user.id,
|
|
value: 82.5,
|
|
});
|
|
expect(logs.find((l) => l.action === 'circumference.removed')?.details).toMatchObject({
|
|
actorId: user.id,
|
|
typeId: 'biceps',
|
|
value: 40,
|
|
});
|
|
});
|
|
|
|
it('lists logs for admin with actor data, newest first', async () => {
|
|
const { token, user } = await registerViaApi();
|
|
const admin = await createUser({ isAdmin: true });
|
|
const adminLogin = await loginViaApi(admin.user.email, admin.password);
|
|
|
|
const res = await buildApp()
|
|
.get('/api/v1/admin/logs')
|
|
.set('Authorization', `Bearer ${adminLogin.token}`);
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.total).toBeGreaterThanOrEqual(1);
|
|
expect(Array.isArray(res.body.logs)).toBe(true);
|
|
|
|
// własny wpis sprawdzamy filtrem userId — przy równoległych testach strona
|
|
// 100 najnowszych logów nie musi zawierać rejestracji tego użytkownika
|
|
const mineRes = await buildApp()
|
|
.get(`/api/v1/admin/logs?userId=${user.id}`)
|
|
.set('Authorization', `Bearer ${adminLogin.token}`);
|
|
expect(mineRes.status).toBe(200);
|
|
const mine = mineRes.body.logs[0];
|
|
expect(mine).toBeTruthy();
|
|
expect(mine.actor).toMatchObject({ email: user.email });
|
|
expect(mine.action).toBe('user.registered');
|
|
|
|
const dates = res.body.logs.map((l: { createdAt: string }) => new Date(l.createdAt).getTime());
|
|
for (let i = 1; i < dates.length; i++) {
|
|
expect(dates[i - 1]).toBeGreaterThanOrEqual(dates[i]);
|
|
}
|
|
});
|
|
|
|
it('filters logs by action and limits the page size', async () => {
|
|
const admin = await createUser({ isAdmin: true });
|
|
const adminLogin = await loginViaApi(admin.user.email, admin.password);
|
|
const app = buildApp();
|
|
const auth = { Authorization: `Bearer ${adminLogin.token}` };
|
|
|
|
const filtered = await app.get('/api/v1/admin/logs?action=user.registered').set(auth);
|
|
expect(filtered.status).toBe(200);
|
|
expect(filtered.body.logs.length).toBeGreaterThan(0);
|
|
for (const l of filtered.body.logs) expect(l.action).toBe('user.registered');
|
|
|
|
const limited = await app.get('/api/v1/admin/logs?limit=1&offset=0').set(auth);
|
|
expect(limited.status).toBe(200);
|
|
expect(limited.body.logs).toHaveLength(1);
|
|
expect(limited.body.total).toBeGreaterThanOrEqual(1);
|
|
});
|
|
|
|
it('rejects invalid query parameters with 400', async () => {
|
|
const admin = await createUser({ isAdmin: true });
|
|
const adminLogin = await loginViaApi(admin.user.email, admin.password);
|
|
const app = buildApp();
|
|
const auth = { Authorization: `Bearer ${adminLogin.token}` };
|
|
|
|
expect((await app.get('/api/v1/admin/logs?limit=0').set(auth)).status).toBe(400);
|
|
expect((await app.get('/api/v1/admin/logs?limit=501').set(auth)).status).toBe(400);
|
|
expect((await app.get('/api/v1/admin/logs?from=2026-1-01').set(auth)).status).toBe(400);
|
|
});
|
|
|
|
it('records login and logout (with client marker)', async () => {
|
|
const { user, password } = await createUser();
|
|
const agent = buildAgent();
|
|
expect((await agent.post('/api/v1/auth/login').send({ email: user.email, password })).status).toBe(200);
|
|
expect((await agent.post('/api/v1/auth/logout')).status).toBe(204);
|
|
|
|
// login panelu admina (nagłówek X-Client) — ten sam action, inny client
|
|
const adminCookie = buildAgent();
|
|
expect(
|
|
(
|
|
await adminCookie
|
|
.post('/api/v1/auth/login')
|
|
.set('X-Client', 'admin')
|
|
.send({ email: user.email, password })
|
|
).status,
|
|
).toBe(200);
|
|
|
|
const logs = await prisma.activityLog.findMany({
|
|
where: { actorId: user.id, action: { in: ['user.logged_in', 'user.logged_out'] } },
|
|
orderBy: { createdAt: 'asc' },
|
|
});
|
|
expect(logs.map((l) => l.action)).toEqual(['user.logged_in', 'user.logged_out', 'user.logged_in']);
|
|
for (const log of logs) {
|
|
expect(log.entityType).toBe('user');
|
|
expect(log.entityId).toBe(user.id);
|
|
}
|
|
expect(logs[0].details).toMatchObject({ actorId: user.id, client: 'app' });
|
|
expect(logs[1].details).toMatchObject({ actorId: user.id, client: 'app' });
|
|
expect(logs[2].details).toMatchObject({ actorId: user.id, client: 'admin' });
|
|
});
|
|
|
|
it('admin account ban logs status change and field names only, never the password', async () => {
|
|
const admin = await createUser({ isAdmin: true });
|
|
const adminLogin = await loginViaApi(admin.user.email, admin.password);
|
|
const target = await createUser();
|
|
const secret = 'Secr3tPass!';
|
|
const res = await buildApp()
|
|
.patch(`/api/v1/admin/users/${target.user.id}`)
|
|
.set('Authorization', `Bearer ${adminLogin.token}`)
|
|
.send({ firstName: 'Zmieniony', password: secret, status: 'BANNED', restrictionReason: 'testowy ban' });
|
|
expect(res.status).toBe(200);
|
|
|
|
const logs = await prisma.activityLog.findMany({ where: { entityId: target.user.id } });
|
|
const updated = logs.find((l) => l.action === 'user.updated');
|
|
const banned = logs.find((l) => l.action === 'user.status.changed');
|
|
expect(updated?.actorId).toBe(admin.user.id);
|
|
// user.updated: tylko NAZWY pól, bez password
|
|
expect(updated?.details).toMatchObject({ fields: ['firstName'] });
|
|
expect(banned?.details).toMatchObject({
|
|
status: 'BANNED',
|
|
restrictionReason: 'testowy ban',
|
|
});
|
|
for (const log of logs) {
|
|
expect(JSON.stringify(log.details ?? {})).not.toContain(secret);
|
|
expect(JSON.stringify(log.details ?? {})).not.toContain('password');
|
|
}
|
|
});
|
|
|
|
it('changing platform roles logs a separate user.roles.changed entry', async () => {
|
|
const admin = await createUser({ isAdmin: true });
|
|
const adminLogin = await loginViaApi(admin.user.email, admin.password);
|
|
const target = await createUser();
|
|
const res = await buildApp()
|
|
.put(`/api/v1/admin/users/${target.user.id}/roles`)
|
|
.set('Authorization', `Bearer ${adminLogin.token}`)
|
|
.send({ roles: ['MODERATOR'] });
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.roles).toEqual(['MODERATOR']);
|
|
|
|
const log = await prisma.activityLog.findFirst({
|
|
where: { entityId: target.user.id, action: 'user.roles.changed' },
|
|
});
|
|
expect(log?.details).toMatchObject({ actorId: admin.user.id, roles: ['MODERATOR'] });
|
|
});
|
|
|
|
it('records membership create/update/delete with roles', async () => {
|
|
const admin = await createUser({ isAdmin: true });
|
|
const adminLogin = await loginViaApi(admin.user.email, admin.password);
|
|
const target = await createUser();
|
|
const gym = await prisma.gym.create({ data: { name: `Audit Gym ${rand()}` } });
|
|
const app = buildApp();
|
|
const auth = { Authorization: `Bearer ${adminLogin.token}` };
|
|
|
|
const created = await app
|
|
.post(`/api/v1/admin/users/${target.user.id}/memberships`)
|
|
.set(auth)
|
|
.send({ gymId: gym.id, roles: ['MEMBER'] });
|
|
expect(created.status).toBe(201);
|
|
const membershipId = created.body.membership.id;
|
|
|
|
const patched = await app
|
|
.patch(`/api/v1/admin/users/${target.user.id}/memberships/${gym.id}`)
|
|
.set(auth)
|
|
.send({ roles: ['TRAINER'] });
|
|
expect(patched.status).toBe(200);
|
|
|
|
const removed = await app
|
|
.delete(`/api/v1/admin/users/${target.user.id}/memberships/${gym.id}`)
|
|
.set(auth);
|
|
expect(removed.status).toBe(204);
|
|
|
|
const logs = await prisma.activityLog.findMany({
|
|
where: { entityId: membershipId },
|
|
orderBy: { createdAt: 'asc' },
|
|
});
|
|
expect(logs.map((l) => l.action)).toEqual([
|
|
'membership.created',
|
|
'membership.updated',
|
|
'membership.deleted',
|
|
]);
|
|
expect(logs[0].entityType).toBe('membership');
|
|
expect(logs[0].details).toMatchObject({
|
|
actorId: admin.user.id,
|
|
userId: target.user.id,
|
|
gymId: gym.id,
|
|
roles: ['MEMBER'],
|
|
});
|
|
expect(logs[1].details).toMatchObject({ roles: ['TRAINER'] });
|
|
// usunięcie: role wyprowadzone z grantów w momencie usuwania (faza 2)
|
|
expect(logs[2].details).toMatchObject({ roles: ['TRAINER', 'MEMBER'] });
|
|
});
|
|
|
|
it('admin gym CRUD logs gym.created/updated/deleted', async () => {
|
|
const admin = await createUser({ isAdmin: true });
|
|
const adminLogin = await loginViaApi(admin.user.email, admin.password);
|
|
const owner = await createUser();
|
|
const app = buildApp();
|
|
const auth = { Authorization: `Bearer ${adminLogin.token}` };
|
|
|
|
const created = await app
|
|
.post('/api/v1/admin/gyms')
|
|
.set(auth)
|
|
.send({
|
|
name: `Admin Audit Gym ${rand()}`,
|
|
ownerId: owner.user.id,
|
|
addressLine1: 'Mokotowska 1',
|
|
postalCode: '00-001',
|
|
city: 'Warszawa',
|
|
});
|
|
expect(created.status).toBe(201);
|
|
const gymId = created.body.gym.id;
|
|
|
|
const patched = await app
|
|
.patch(`/api/v1/admin/gyms/${gymId}`)
|
|
.set(auth)
|
|
.send({ name: 'Admin Audit Gym Renamed', availability: null });
|
|
expect(patched.status).toBe(200);
|
|
|
|
const deleted = await app.delete(`/api/v1/admin/gyms/${gymId}`).set(auth);
|
|
expect(deleted.status).toBe(204);
|
|
|
|
const logs = await prisma.activityLog.findMany({
|
|
where: { entityId: gymId },
|
|
orderBy: { createdAt: 'asc' },
|
|
});
|
|
expect(logs.map((l) => l.action)).toEqual(['gym.created', 'gym.updated', 'gym.deleted']);
|
|
expect(logs[0].entityType).toBe('gym');
|
|
expect(logs[0].details).toMatchObject({ actorId: admin.user.id, name: created.body.gym.name });
|
|
expect(logs[2].details).toMatchObject({ name: 'Admin Audit Gym Renamed' });
|
|
|
|
// ścieżka admina używa identycznych stringów akcji jak ścieżka właściciela
|
|
const sameStrings = await prisma.activityLog.count({
|
|
where: { actorId: admin.user.id, action: { in: ['gym.created', 'gym.updated', 'gym.deleted'] } },
|
|
});
|
|
expect(sameStrings).toBeGreaterThanOrEqual(3);
|
|
});
|
|
|
|
it('records a trainer comment (added, with traineeId) and its deletion', async () => {
|
|
const trainer = await createUserWithToken({ firstName: 'Tomasz' });
|
|
const trainee = await createUserWithToken({ firstName: 'Anna' });
|
|
const gym = await prisma.gym.create({ data: { name: `Cmt Audit Gym ${rand()}` } });
|
|
await createMembership(trainer.user.id, gym.id, ['TRAINER']);
|
|
await prisma.gymMembership.create({ data: { userId: trainee.user.id, gymId: gym.id } });
|
|
const app = buildApp();
|
|
|
|
const invite = await app
|
|
.post('/api/v1/trainer/invitations')
|
|
.set('Authorization', `Bearer ${trainer.token}`)
|
|
.send({ userId: trainee.user.id });
|
|
expect(invite.status).toBe(201);
|
|
const accept = await app
|
|
.post(`/api/v1/trainer/invitations/${invite.body.coaching.id}/accept`)
|
|
.set('Authorization', `Bearer ${trainee.token}`);
|
|
expect(accept.status).toBe(200);
|
|
|
|
const exercise = await createExercise();
|
|
const plan = await seedPlan({
|
|
userId: trainee.user.id,
|
|
weeks: [{ index: 0, days: [{ dayOfWeek: 1, exercises: [{ exerciseId: exercise.id, order: 0 }] }] }],
|
|
});
|
|
const done = await seedSession(plan.weeks[0].days[0].id, { status: 'COMPLETED' });
|
|
|
|
const added = await app
|
|
.post(`/api/v1/trainer/trainees/${trainee.user.id}/comments`)
|
|
.set('Authorization', `Bearer ${trainer.token}`)
|
|
.send({ sessionId: done.id, body: 'Audit comment' });
|
|
expect(added.status).toBe(201);
|
|
const commentId = added.body.comment.id;
|
|
|
|
const deleted = await app
|
|
.delete(`/api/v1/trainer/trainees/${trainee.user.id}/comments/${commentId}`)
|
|
.set('Authorization', `Bearer ${trainer.token}`);
|
|
expect(deleted.status).toBe(204);
|
|
|
|
const logs = await prisma.activityLog.findMany({
|
|
where: { entityId: commentId },
|
|
orderBy: { createdAt: 'asc' },
|
|
});
|
|
expect(logs.map((l) => l.action)).toEqual(['comment.added', 'comment.deleted']);
|
|
expect(logs[0].entityType).toBe('comment');
|
|
expect(logs[0].details).toMatchObject({ actorId: trainer.user.id, traineeId: trainee.user.id });
|
|
expect(logs[1].details).toMatchObject({ traineeId: trainee.user.id });
|
|
});
|
|
});
|
|
|
|
describe('activity logs — zakres strumienia konta (GET /admin/users/:id/activity?scope=)', () => {
|
|
it('default = na koncie; performed = akcje użytkownika; all = unia obu strumieni', async () => {
|
|
const admin = await createUser({ isAdmin: true });
|
|
const adminLogin = await loginViaApi(admin.user.email, admin.password);
|
|
const { token, user } = await registerViaApi();
|
|
const plan = await seedPlan({
|
|
userId: user.id,
|
|
status: 'ACTIVE',
|
|
startDate: new Date(MONDAY),
|
|
weeks: [{ index: 0, days: [{ dayOfWeek: 1, date: new Date(MONDAY) }] }],
|
|
});
|
|
const app = buildApp();
|
|
|
|
// akcja WYKONANA przez usera (entityType session — poza strumieniem „na koncie")
|
|
const started = await app
|
|
.post(`/api/v1/days/${plan.weeks[0].days[0].id}/sessions`)
|
|
.set('Authorization', `Bearer ${token}`);
|
|
expect(started.status).toBe(201);
|
|
// akcja WYKONANA NA userze przez admina (actor = admin)
|
|
const edit = await app
|
|
.patch(`/api/v1/admin/users/${user.id}`)
|
|
.set('Authorization', `Bearer ${adminLogin.token}`)
|
|
.send({ firstName: 'Po edycji' });
|
|
expect(edit.status).toBe(200);
|
|
|
|
const auth = { Authorization: `Bearer ${adminLogin.token}` };
|
|
const actionsOf = async (qs: string) => {
|
|
const res = await app.get(`/api/v1/admin/users/${user.id}/activity${qs}`).set(auth);
|
|
expect(res.status).toBe(200);
|
|
return res.body.logs.map((l: { action: string }) => l.action);
|
|
};
|
|
|
|
// domyślnie bez zmian (kompatybilność): tylko operacje NA koncie
|
|
const def = await actionsOf('');
|
|
expect(def).toContain('user.updated');
|
|
expect(def).toContain('user.registered');
|
|
expect(def).not.toContain('session.started');
|
|
|
|
const performed = await actionsOf('?scope=performed');
|
|
expect(performed).toContain('session.started');
|
|
expect(performed).toContain('user.registered');
|
|
expect(performed).not.toContain('user.updated');
|
|
|
|
const all = await actionsOf('?scope=all');
|
|
expect(all).toContain('session.started');
|
|
expect(all).toContain('user.updated');
|
|
expect(all).toContain('user.registered');
|
|
});
|
|
|
|
it('odrzuca nieznany scope z 400', async () => {
|
|
const admin = await createUser({ isAdmin: true });
|
|
const adminLogin = await loginViaApi(admin.user.email, admin.password);
|
|
const { user } = await registerViaApi();
|
|
const res = await buildApp()
|
|
.get(`/api/v1/admin/users/${user.id}/activity?scope=whatever`)
|
|
.set('Authorization', `Bearer ${adminLogin.token}`);
|
|
expect(res.status).toBe(400);
|
|
});
|
|
});
|