Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/lovely-shirts-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/rest-typings': patch
'@rocket.chat/meteor': patch
---

Fix an issue where the report exported in the App logs page would not consider the instance id filter
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const testCases = Object.values(composeStories(stories)).map((Story) => [Story.s
const onConfirm = jest.fn();
const { Default } = composeStories(stories);

afterEach(() => {
jest.clearAllMocks();
});

test.each(testCases)(`renders without crashing`, async (_storyname, Story) => {
const view = render(<Story />, {
wrapper: mockAppRoot().build(),
Expand All @@ -35,3 +39,22 @@ it('should send the correct payload to the endpoint', async () => {
expect(onConfirm).toHaveBeenCalledTimes(1);
expect(onConfirm).toHaveBeenCalledWith('/api/apps/undefined/export-logs?count=2000&type=json');
});

it('should include instance filter in the payload to endpoint', async () => {
render(
<Default
onConfirm={onConfirm}
filterValues={{
instance: '123',
}}
/>,
{
wrapper: mockAppRoot().build(),
},
);

expect(screen.getByRole('button', { name: 'Download' })).toBeInTheDocument();
await userEvent.click(screen.getByRole('button', { name: 'Download' }));
expect(onConfirm).toHaveBeenCalledTimes(1);
expect(onConfirm).toHaveBeenCalledWith('/api/apps/undefined/export-logs?instanceId=123&count=2000&type=json');
});
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const ExportLogsModal = ({ onClose, filterValues, onConfirm }: ExportLogs
const getFileUrl = ({
severity,
event,
instance,
startDate,
endDate,
count,
Expand All @@ -71,6 +72,9 @@ export const ExportLogsModal = ({ onClose, filterValues, onConfirm }: ExportLogs
if (event && event !== 'all') {
baseUrl += `method=${event}&`;
}
if (instance && instance !== 'all') {
baseUrl += `instanceId=${instance}&`;
}
if (startDate) {
baseUrl += `startDate=${new Date(`${startDate}T${startTime}`).toISOString()}&`;
}
Expand Down
7 changes: 7 additions & 0 deletions apps/meteor/tests/data/api-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export function log(res: Response) {
});
}

let instanceId: string | undefined;

export function getCredentials(done?: CallbackHandler) {
void request
.post(api('login'))
Expand All @@ -75,6 +77,11 @@ export function getCredentials(done?: CallbackHandler) {
.expect((res) => {
credentials['X-Auth-Token'] = res.body.data.authToken;
credentials['X-User-Id'] = res.body.data.userId;
instanceId = res.headers['x-instance-id'];
})
.end(done);
}

export function getInstanceId() {
return instanceId;
}
21 changes: 20 additions & 1 deletion apps/meteor/tests/end-to-end/apps/app-logs-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { App } from '@rocket.chat/core-typings';
import { expect } from 'chai';
import { after, before, describe, it } from 'mocha';

import { getCredentials, request, credentials } from '../../data/api-data';
import { getCredentials, request, credentials, getInstanceId } from '../../data/api-data';
import { apps } from '../../data/apps/apps-data';
import { installTestApp, cleanupApps } from '../../data/apps/helper';
import { IS_EE } from '../../e2e/config/constants';
Expand Down Expand Up @@ -168,6 +168,25 @@ import { IS_EE } from '../../e2e/config/constants';
.end(done);
});

it('should export app logs filtered by instance id', (done) => {
const instanceId = getInstanceId();
void request
.get(apps(`/${app.id}/export-logs`))
.query({ instanceId, type: 'json' })
.set(credentials)
.expect('Content-Type', 'text/plain')
.expect(200)
.expect((res) => {
const logs = JSON.parse(res.text);
expect(logs).to.be.an('array');

logs.forEach((log: ILoggerStorageEntry) => {
expect(log.instanceId).to.equal(instanceId);
});
})
.end(done);
});

it('should export app logs filtered by date range', (done) => {
const startDate = new Date();
startDate.setDate(startDate.getDate() - 1); // 1 day ago
Expand Down
1 change: 1 addition & 0 deletions packages/rest-typings/src/apps/appLogsExportProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const AppLogsExportPropsSchema = {
properties: {
logLevel: { type: 'string', enum: ['0', '1', '2'], nullable: true },
method: { type: 'string', nullable: true },
instanceId: { type: 'string', nullable: true },
startDate: { type: 'string', format: 'date-time', nullable: true },
endDate: { type: 'string', format: 'date-time', nullable: true },
type: { type: 'string', enum: ['json', 'csv'] },
Expand Down
Loading