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
3 changes: 2 additions & 1 deletion packages/agent/src/utils/query-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ValidationError,
} from '@forestadmin/datasource-toolkit';
import { Context } from 'koa';
import { v4 as uuidv4 } from 'uuid';

import ConditionTreeParser from './condition-tree-parser';

Expand Down Expand Up @@ -139,7 +140,7 @@ export default class QueryStringParser {
QueryStringParser.VALID_TIMEZONES.add(timezone);
}

return { ...context.state.user, timezone };
return { ...context.state.user, timezone, requestId: uuidv4() };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

}

static parsePagination(context: Context): Page {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('CollectionApiChartRoute', () => {
await route.handleApiChart(context);

expect(dataSource.getCollection('books').renderChart).toHaveBeenCalledWith(
{ email: 'marty@doclabs.com', timezone: 'Europe/Paris' },
{ email: 'marty@doclabs.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
'myChart',
[123],
);
Expand All @@ -71,7 +71,7 @@ describe('CollectionApiChartRoute', () => {
await route.handleSmartChart(context);

expect(dataSource.getCollection('books').renderChart).toHaveBeenCalledWith(
{ email: 'marty@doclabs.com', timezone: 'Europe/Paris' },
{ email: 'marty@doclabs.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
'myChart',
[123],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('DataSourceApiChartRoute', () => {
await route.handleApiChart(context);

expect(dataSource.renderChart).toHaveBeenCalledWith(
{ email: 'marty@doclabs.com', timezone: 'Europe/Paris' },
{ email: 'marty@doclabs.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
'myChart',
);
expect(context.response.body).toMatchObject({
Expand All @@ -63,7 +63,7 @@ describe('DataSourceApiChartRoute', () => {
await route.handleSmartChart(context);

expect(dataSource.renderChart).toHaveBeenCalledWith(
{ email: 'marty@doclabs.com', timezone: 'Europe/Paris' },
{ email: 'marty@doclabs.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
'myChart',
);
expect(context.response.body).toStrictEqual({ countCurrent: 12 });
Expand Down
30 changes: 17 additions & 13 deletions packages/agent/test/routes/access/chart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ ...user, timezone: 'Europe/Paris' },
{ ...user, requestId: expect.any(String), timezone: 'Europe/Paris' },
{ conditionTree: null, search: null, searchExtended: false, segment: null },
{ field: undefined, groups: undefined, operation: 'Count' },
);
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('ChartRoute', () => {

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledTimes(1);
expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ ...user, timezone: 'Europe/Paris' },
{ ...user, requestId: expect.any(String), timezone: 'Europe/Paris' },
{
conditionTree: { field: 'name', operator: 'Present', value: null },
search: null,
Expand Down Expand Up @@ -298,7 +298,11 @@ describe('ChartRoute', () => {

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledTimes(1);
expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{
email: 'john.doe@domain.com',
requestId: expect.any(String),
timezone: 'Europe/Paris',
},
{
conditionTree: {
aggregator: 'And',
Expand Down Expand Up @@ -382,7 +386,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ ...user, timezone: 'Europe/Paris' },
{ ...user, requestId: expect.any(String), timezone: 'Europe/Paris' },
{ conditionTree: null, search: null, searchExtended: false, segment: null },
{ field: undefined, groups: undefined, operation: 'Count' },
);
Expand Down Expand Up @@ -423,7 +427,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
conditionTree: { field: 'title', operator: 'NotContains', value: '[test]' },
search: null,
Expand Down Expand Up @@ -467,7 +471,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ ...user, timezone: 'Europe/Paris' },
{ ...user, requestId: expect.any(String), timezone: 'Europe/Paris' },
{ conditionTree: null, search: null, searchExtended: false, segment: null },
{ field: undefined, groups: [{ field: 'author:firstName' }], operation: 'Count' },
);
Expand Down Expand Up @@ -519,7 +523,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
conditionTree: { field: 'title', operator: 'NotContains', value: '[test]' },
search: null,
Expand Down Expand Up @@ -573,7 +577,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ ...user, timezone: 'Europe/Paris' },
{ ...user, requestId: expect.any(String), timezone: 'Europe/Paris' },
{
conditionTree: factories.conditionTreeLeaf.build({
operator: 'Present',
Expand Down Expand Up @@ -638,7 +642,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ ...user, timezone: 'Europe/Paris' },
{ ...user, requestId: expect.any(String), timezone: 'Europe/Paris' },
{
conditionTree: factories.conditionTreeBranch.build({
aggregator: 'And',
Expand Down Expand Up @@ -712,7 +716,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ ...user, timezone: 'Europe/Paris' },
{ ...user, requestId: expect.any(String), timezone: 'Europe/Paris' },
{ conditionTree: null, search: null, searchExtended: false, segment: null },
{ field: 'id', groups: [{ field: 'author:id' }], operation: 'Sum' },
2,
Expand Down Expand Up @@ -758,7 +762,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ ...user, timezone: 'Europe/Paris' },
{ ...user, requestId: expect.any(String), timezone: 'Europe/Paris' },
{ conditionTree: null, search: null, searchExtended: false, segment: null },
{ operation: 'Count', field: null, groups: [{ field: 'publisher:id' }] },
2,
Expand Down Expand Up @@ -811,7 +815,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
conditionTree: {
field: 'author:name',
Expand Down Expand Up @@ -868,7 +872,7 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ ...user, timezone: 'Europe/Paris' },
{ ...user, requestId: expect.any(String), timezone: 'Europe/Paris' },
{ conditionTree: null, search: null, searchExtended: false, segment: null },
{ groups: [{ field: 'author:id' }], operation: 'Count' },
2,
Expand Down
4 changes: 2 additions & 2 deletions packages/agent/test/routes/access/count-related.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('CountRelatedRoute', () => {
dataSource.getCollection('books'),
['2d162303-78bf-599e-b197-93590ac3d315'],
'myBookPersons',
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
new Filter({
search: 'searched argument',
searchExtended: false,
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('CountRelatedRoute', () => {
dataSource.getCollection('books'),
['2d162303-78bf-599e-b197-93590ac3d315'],
'myBookPersons',
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
new Filter({
search: 'searched argument',
searchExtended: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/agent/test/routes/access/count.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('CountRoute', () => {
await count.handleCount(context);

expect(aggregateSpy).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{ conditionTree: null, search: null, searchExtended: false, segment: null },
{ operation: 'Count' },
);
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('CountRoute', () => {
await count.handleCount(context);

expect(aggregateSpy).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
conditionTree: {
field: 'title',
Expand Down
8 changes: 4 additions & 4 deletions packages/agent/test/routes/access/csv-related.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('CsvRelatedRoute', () => {

await readCsv(context.response.body as AsyncGenerator<string>);
expect(csvGenerator).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
new Projection('id', 'name'),
'id,name',
paginatedFilter,
Expand All @@ -134,7 +134,7 @@ describe('CsvRelatedRoute', () => {
dataSource.getCollection('books'),
['123e4567-e89b-12d3-a456-111111111111'],
'myPersons',
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
expect.any(PaginatedFilter),
expect.any(Projection),
);
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('CsvRelatedRoute', () => {

await readCsv(context.response.body as AsyncGenerator<string>);
expect(csvGenerator).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
new Projection('id', 'name'),
'id,name',
paginatedFilter,
Expand All @@ -228,7 +228,7 @@ describe('CsvRelatedRoute', () => {
dataSource.getCollection('books'),
['123e4567-e89b-12d3-a456-111111111111'],
'myPersons',
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
expect.any(PaginatedFilter),
expect.any(Projection),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/test/routes/access/csv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('CsvRoute', () => {

await readCsv(context.response.body as AsyncGenerator<string>);
expect(csvGenerator).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
['id', 'name'],
'id,name',
paginatedFilter,
Expand Down
5 changes: 2 additions & 3 deletions packages/agent/test/routes/access/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { createMockContext } from '@shopify/jest-koa-mocks';

import Get from '../../../src/routes/access/get';
import { HttpCode } from '../../../src/types';
import QueryStringParser from '../../../src/utils/query-string';
import * as factories from '../../__factories__';

describe('GetRoute', () => {
Expand Down Expand Up @@ -67,7 +66,7 @@ describe('GetRoute', () => {
await get.handleGet(context);

expect(dataSource.getCollection('books').list).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
conditionTree: {
field: 'id',
Expand Down Expand Up @@ -128,7 +127,7 @@ describe('GetRoute', () => {
);

expect(dataSource.getCollection('books').list).toHaveBeenCalledWith(
QueryStringParser.parseCaller(context),
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
new PaginatedFilter({
conditionTree: ConditionTreeFactory.fromPlainObject({
aggregator: 'And',
Expand Down
4 changes: 2 additions & 2 deletions packages/agent/test/routes/access/list-related.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('ListRelatedRoute', () => {
dataSource.getCollection('books'),
['2d162303-78bf-599e-b197-93590ac3d315'],
'myPersons',
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
new PaginatedFilter({
search: 'aName',
searchExtended: false,
Expand Down Expand Up @@ -208,7 +208,7 @@ describe('ListRelatedRoute', () => {
dataSource.getCollection('books'),
['2d162303-78bf-599e-b197-93590ac3d315'],
'myPersons',
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
new PaginatedFilter({
search: 'aName',
searchExtended: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/agent/test/routes/access/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('ListRoute', () => {

// then
expect(collection.list).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
conditionTree: null,
search: '2',
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('ListRoute', () => {

// then
expect(collection.list).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', timezone: 'Europe/Paris' },
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
conditionTree: {
field: 'title',
Expand Down
Loading