-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
api/test/unit/bigquery-query-builder/bigquery-query-builder.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { DataSource, SelectQueryBuilder } from 'typeorm'; | ||
import { BigQueryAlertsQueryBuilder } from '../../../src/modules/eudr-alerts/alerts-query-builder/big-query-alerts-query.builder'; | ||
import { typeOrmConfig } from '../../../src/typeorm.config'; | ||
|
||
describe('BigQueryAlertsQueryBuilder', () => { | ||
let queryBuilder: SelectQueryBuilder<any>; | ||
const dataSource = new DataSource(typeOrmConfig); | ||
|
||
beforeEach(() => { | ||
queryBuilder = dataSource.createQueryBuilder().from('falsetable', 'alerts'); | ||
}); | ||
test('without DTO parameters should return a select with table name and alias', () => { | ||
const bigQueryBuilder = new BigQueryAlertsQueryBuilder(queryBuilder); | ||
const result = bigQueryBuilder.buildQuery(); | ||
expect(result.query).toBe('SELECT * FROM falsetable alerts'); | ||
expect(result.params).toEqual([]); | ||
}); | ||
|
||
test('with date range parameters should add a where statement with parsed DATE formats', () => { | ||
const bigQueryBuilder = new BigQueryAlertsQueryBuilder(queryBuilder, { | ||
startAlertDate: new Date('2020-01-01'), | ||
endAlertDate: new Date('2020-01-31'), | ||
}); | ||
const result = bigQueryBuilder.buildQuery(); | ||
expect(result.query).toContain( | ||
'WHERE DATE(alertdate) BETWEEN DATE(?) AND DATE(?)', | ||
); | ||
}); | ||
|
||
test('with a single supplier id should add a WHERE IN statement with a single parameter', () => { | ||
const bigQueryBuilder = new BigQueryAlertsQueryBuilder(queryBuilder, { | ||
supplierIds: ['supplier1'], | ||
}); | ||
const result = bigQueryBuilder.buildQuery(); | ||
expect(result.query).toContain('WHERE supplierid IN (?)'); | ||
expect(result.params).toEqual(['supplier1']); | ||
}); | ||
|
||
test('with 2 supplier id should add a WHERE IN statement with 2 parameters', () => { | ||
const bigQueryBuilder = new BigQueryAlertsQueryBuilder(queryBuilder, { | ||
supplierIds: ['supplier1', 'supplier2'], | ||
}); | ||
const result = bigQueryBuilder.buildQuery(); | ||
expect(result.query).toContain('WHERE supplierid IN (?, ?)'); | ||
expect(result.params).toEqual(['supplier1', 'supplier2']); | ||
}); | ||
}); |