Add reporting features with new report engine and bookmark management
- Introduced a comprehensive report engine for generating and managing reports, including sales and logistics reports. - Added new API endpoints for retrieving report configurations, data, and metadata, ensuring secure access with privilege checks. - Implemented a report bookmarks system to allow users to save and manage report filters and configurations. - Created database migrations for the `report_bookmarks` table and updated the schema to support new report functionalities. - Developed services and controllers for handling report queries and bookmarks, including CRUD operations for bookmarks. - Enhanced API documentation to reflect the new reporting features and endpoints. - Added unit and integration tests to validate the new functionalities and ensure data integrity across report operations.
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import request from 'supertest';
|
||||
import { App } from 'supertest/types';
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { configureApp } from '../src/common/configure-app';
|
||||
import { DRIZZLE, type DrizzleDB } from '../src/database/database.module';
|
||||
import {
|
||||
privilegeDetails,
|
||||
privilegeKeys,
|
||||
privileges,
|
||||
users,
|
||||
} from '../src/database/schema';
|
||||
import { REPORT_BOOKMARK_TYPE } from '../src/modules/reports/shared/constants/bookmark-type';
|
||||
import { REPORT_GROUP } from '../src/modules/reports/shared/constants/report-group';
|
||||
import { PRIVILEGE_ACTIONS } from '../src/modules/privileges/privilege-action';
|
||||
import { registerAndActivate } from './helpers/activate-user';
|
||||
|
||||
describe('Report bookmarks (e2e)', () => {
|
||||
let app: INestApplication<App>;
|
||||
let db: DrizzleDB;
|
||||
|
||||
const password = 'password123';
|
||||
const adminUsername = `bookmark_admin_${Date.now()}`;
|
||||
|
||||
let adminAccessToken: string;
|
||||
let adminUserId: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
configureApp(app, {
|
||||
NODE_ENV: 'test',
|
||||
SWAGGER_ENABLED: 'false',
|
||||
});
|
||||
await app.init();
|
||||
db = app.get(DRIZZLE);
|
||||
|
||||
const admin = await registerAndActivate(app, db, adminUsername, password);
|
||||
adminAccessToken = admin.accessToken;
|
||||
adminUserId = admin.userId;
|
||||
|
||||
const now = Date.now();
|
||||
const [priv] = await db
|
||||
.insert(privileges)
|
||||
.values({
|
||||
name: 'Bookmark Admin',
|
||||
code: `BOOKMARK_ADMIN_${now}`,
|
||||
status: 'active',
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
createdBy: adminUserId,
|
||||
updatedBy: adminUserId,
|
||||
})
|
||||
.returning();
|
||||
|
||||
const keys = await db.select().from(privilegeKeys);
|
||||
const detailRows = keys.flatMap((key) =>
|
||||
PRIVILEGE_ACTIONS.map((action) => ({
|
||||
privilegeId: priv.id,
|
||||
privilegeKeyId: key.id,
|
||||
action,
|
||||
value: true,
|
||||
})),
|
||||
);
|
||||
await db.insert(privilegeDetails).values(detailRows);
|
||||
|
||||
await db
|
||||
.update(users)
|
||||
.set({ privilegeId: priv.id, updatedAt: Date.now() })
|
||||
.where(eq(users.id, adminUserId));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it('creates, applies, and unapplies a filter bookmark', async () => {
|
||||
const uniqueName = 'sales_report__sales_order';
|
||||
const create = await request(app.getHttpServer())
|
||||
.post('/report-bookmarks')
|
||||
.set('Authorization', `Bearer ${adminAccessToken}`)
|
||||
.send({
|
||||
groupName: REPORT_GROUP.SALES_REPORT,
|
||||
uniqueName,
|
||||
label: 'My filter',
|
||||
type: REPORT_BOOKMARK_TYPE.FILTER_TABLE,
|
||||
applied: true,
|
||||
configuration: { main__status: 'active' },
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
const bookmarkId = create.body.id as string;
|
||||
|
||||
const second = await request(app.getHttpServer())
|
||||
.post('/report-bookmarks')
|
||||
.set('Authorization', `Bearer ${adminAccessToken}`)
|
||||
.send({
|
||||
groupName: REPORT_GROUP.SALES_REPORT,
|
||||
uniqueName,
|
||||
label: 'Second filter',
|
||||
type: REPORT_BOOKMARK_TYPE.FILTER_TABLE,
|
||||
applied: true,
|
||||
configuration: { main__status: 'draft' },
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.put(`/report-bookmarks/applied/${second.body.id}`)
|
||||
.set('Authorization', `Bearer ${adminAccessToken}`)
|
||||
.expect(200);
|
||||
|
||||
const applied = await request(app.getHttpServer())
|
||||
.get('/report-bookmarks/applied')
|
||||
.query({
|
||||
groupName: REPORT_GROUP.SALES_REPORT,
|
||||
uniqueName,
|
||||
type: REPORT_BOOKMARK_TYPE.FILTER_TABLE,
|
||||
})
|
||||
.set('Authorization', `Bearer ${adminAccessToken}`)
|
||||
.expect(200);
|
||||
|
||||
expect(applied.body.id).toBe(second.body.id);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.put(`/report-bookmarks/unapplied/${bookmarkId}`)
|
||||
.set('Authorization', `Bearer ${adminAccessToken}`)
|
||||
.expect(200);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.delete(`/report-bookmarks/${bookmarkId}`)
|
||||
.set('Authorization', `Bearer ${adminAccessToken}`)
|
||||
.expect(204);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user