Skip to content

Commit

Permalink
fix: lots of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Enki Pontvianne committed Oct 18, 2024
1 parent b16a2ec commit abf22c3
Show file tree
Hide file tree
Showing 21 changed files with 359 additions and 62 deletions.
1 change: 0 additions & 1 deletion packages/_example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ services:
mssql:
image: mcr.microsoft.com/azure-sql-edge
container_name: forest_agent_example_mssql
user: root
ports:
- '1433:1433'
environment:
Expand Down
9 changes: 3 additions & 6 deletions packages/_example/src/forest/customizations/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ export default (collection: CardCustomizer) =>
collection
.addManyToOneRelation('customer', 'customer', { foreignKey: 'customer_id' })
.addAction('Create new card', {
scope: 'Single',
scope: 'Global',
execute: (context, resultBuilder) => {
return resultBuilder.success('ok');
},
form: [
{
type: 'Layout',
component: 'Page',
nextButtonLabel: 'go to next page',
previousButtonLabel: 'back',
elements: [
{
type: 'String',
Expand Down Expand Up @@ -61,8 +59,8 @@ export default (collection: CardCustomizer) =>
{
type: 'Layout',
component: 'Page',
nextButtonLabel: 'go to next page (finalisation, setup of card properties)',
previousButtonLabel: 'return to previous page (selection of the card plan)',
nextButtonLabel: 'go to next page',
previousButtonLabel: 'go to previous page',
elements: [
{
type: 'Layout',
Expand All @@ -79,7 +77,6 @@ export default (collection: CardCustomizer) =>
{
type: 'Layout',
component: 'Page',
previousButtonLabel: 'return to previous page (useless empty page)',
elements: [
{
type: 'Number',
Expand Down
14 changes: 12 additions & 2 deletions packages/agent/test/routes/access/api-chart-collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ describe('CollectionApiChartRoute', () => {
await route.handleApiChart(context);

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

expect(dataSource.getCollection('books').renderChart).toHaveBeenCalledWith(
{ email: 'marty@doclabs.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: 'marty@doclabs.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
'myChart',
[123],
);
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: 'marty@doclabs.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: 'marty@doclabs.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
'myChart',
);
expect(context.response.body).toMatchObject({
Expand All @@ -64,7 +69,12 @@ describe('DataSourceApiChartRoute', () => {
await route.handleSmartChart(context);

expect(dataSource.renderChart).toHaveBeenCalledWith(
{ email: 'marty@doclabs.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: 'marty@doclabs.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
'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 @@ -126,7 +126,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),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{ conditionTree: null, search: null, searchExtended: false, segment: null },
{ field: undefined, groups: undefined, operation: 'Count' },
);
Expand Down Expand Up @@ -259,7 +264,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),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{
conditionTree: { field: 'name', operator: 'Present', value: null },
search: null,
Expand Down Expand Up @@ -308,6 +318,7 @@ describe('ChartRoute', () => {
{
email: 'john.doe@domain.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{
Expand Down Expand Up @@ -393,7 +404,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),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{ conditionTree: null, search: null, searchExtended: false, segment: null },
{ field: undefined, groups: undefined, operation: 'Count' },
);
Expand Down Expand Up @@ -434,7 +450,12 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: 'john.doe@domain.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{
conditionTree: { field: 'title', operator: 'NotContains', value: '[test]' },
search: null,
Expand Down Expand Up @@ -478,7 +499,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),
request: { ip: 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 @@ -530,7 +556,12 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: 'john.doe@domain.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{
conditionTree: { field: 'title', operator: 'NotContains', value: '[test]' },
search: null,
Expand Down Expand Up @@ -584,7 +615,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),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{
conditionTree: factories.conditionTreeLeaf.build({
operator: 'Present',
Expand Down Expand Up @@ -649,7 +685,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),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{
conditionTree: factories.conditionTreeBranch.build({
aggregator: 'And',
Expand Down Expand Up @@ -723,7 +764,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),
request: { ip: 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 @@ -769,7 +815,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),
request: { ip: 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 @@ -822,7 +873,12 @@ describe('ChartRoute', () => {
await chart.handleChart(context);

expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith(
{ email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: 'john.doe@domain.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{
conditionTree: {
field: 'author:name',
Expand Down Expand Up @@ -879,7 +935,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),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{ 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: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: 'john.doe@domain.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
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: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: 'john.doe@domain.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
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: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: 'john.doe@domain.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{ 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: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' },
{
email: 'john.doe@domain.com',
requestId: expect.any(String),
request: { ip: expect.any(String) },
timezone: 'Europe/Paris',
},
{
conditionTree: {
field: 'title',
Expand Down
28 changes: 24 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,12 @@ describe('CsvRelatedRoute', () => {

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

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

0 comments on commit abf22c3

Please sign in to comment.