Skip to content
Open
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
7 changes: 6 additions & 1 deletion packages/agent/src/utils/query-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ export default class QueryStringParser {
QueryStringParser.VALID_TIMEZONES.add(timezone);
}

return { ...context.state.user, timezone, requestId: uuidv4() };
return {
...context.state.user,
timezone,
requestId: uuidv4(),
webAppURL: new URL(context.originalUrl),
};
}

static parsePagination(context: Context): Page {
Expand Down
14 changes: 12 additions & 2 deletions packages/agent/test/routes/access/api-chart-datasource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ describe('DataSourceApiChartRoute', () => {
await route.handleApiChart(context);

expect(dataSource.renderChart).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
'myChart',
);
expect(context.response.body).toMatchObject({
Expand All @@ -64,7 +69,12 @@ describe('DataSourceApiChartRoute', () => {
await route.handleSmartChart(context);

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

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

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledTimes(1);
expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ ...user, requestId: expect.any(String), timezone: 'Europe/Paris' },
{
...user,
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
{
conditionTree: { field: 'name', operator: 'Present', value: null },
search: null,
Expand Down Expand Up @@ -303,6 +313,7 @@ describe('ChartRoute', () => {
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
{
conditionTree: {
Expand Down Expand Up @@ -387,7 +398,12 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

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

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

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

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

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

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

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

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

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
{
conditionTree: {
field: 'author:name',
Expand Down Expand Up @@ -873,7 +929,12 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

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

expect(aggregateSpy).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
{ conditionTree: null, search: null, searchExtended: false, segment: null },
{ operation: 'Count' },
);
Expand Down Expand Up @@ -75,7 +80,12 @@ describe('CountRoute', () => {
await count.handleCount(context);

expect(aggregateSpy).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
{
conditionTree: {
field: 'title',
Expand Down
14 changes: 12 additions & 2 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,12 @@ describe('CsvRelatedRoute', () => {

await readCsv(context.response.body as AsyncGenerator<string>);
expect(csvGenerator).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
new Projection('id', 'name'),
'id,name',
paginatedFilter,
Expand Down Expand Up @@ -216,7 +221,12 @@ describe('CsvRelatedRoute', () => {

await readCsv(context.response.body as AsyncGenerator<string>);
expect(csvGenerator).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
new Projection('id', 'name'),
'id,name',
paginatedFilter,
Expand Down
7 changes: 6 additions & 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,12 @@ describe('CsvRoute', () => {

await readCsv(context.response.body as AsyncGenerator<string>);
expect(csvGenerator).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
['id', 'name'],
'id,name',
paginatedFilter,
Expand Down
14 changes: 12 additions & 2 deletions packages/agent/test/routes/access/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ describe('GetRoute', () => {
await get.handleGet(context);

expect(dataSource.getCollection('books').list).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
{
conditionTree: {
field: 'id',
Expand Down Expand Up @@ -134,7 +139,12 @@ describe('GetRoute', () => {
);

expect(dataSource.getCollection('books').list).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
new PaginatedFilter({
conditionTree: ConditionTreeFactory.fromPlainObject({
aggregator: 'And',
Expand Down
14 changes: 12 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,12 @@ describe('ListRelatedRoute', () => {
dataSource.getCollection('books'),
['2d162303-78bf-599e-b197-93590ac3d315'],
'myPersons',
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
new PaginatedFilter({
search: 'aName',
searchExtended: false,
Expand Down Expand Up @@ -208,7 +213,12 @@ describe('ListRelatedRoute', () => {
dataSource.getCollection('books'),
['2d162303-78bf-599e-b197-93590ac3d315'],
'myPersons',
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com/',
},
new PaginatedFilter({
search: 'aName',
searchExtended: false,
Expand Down
14 changes: 12 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,12 @@ describe('ListRoute', () => {

// then
expect(collection.list).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com',
},
{
conditionTree: null,
search: '2',
Expand Down Expand Up @@ -113,7 +118,12 @@ describe('ListRoute', () => {

// then
expect(collection.list).toHaveBeenCalledWith(
{ email: '[email protected]', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: '[email protected]',
requestId: expect.any(String),
timezone: 'Europe/Paris',
webAppURL: 'http://test.com',
},
{
conditionTree: {
field: 'title',
Expand Down
Loading