Skip to content

Commit 3fab7b7

Browse files
chore: project refactoring
1 parent 699e601 commit 3fab7b7

21 files changed

+1335
-68
lines changed

jest.config.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{
2-
"moduleFileExtensions": [
3-
"js",
4-
"json",
5-
"ts"
6-
],
7-
"modulePaths": [
8-
"<rootDir>",
9-
"src"
10-
],
2+
"moduleFileExtensions": ["js", "json", "ts"],
3+
"modulePaths": ["<rootDir>", "src"],
4+
"moduleNameMapper": {
5+
"^lib/(.*)$": ["<rootDir>/src/lib/$1"],
6+
"^nestjs/(.*)$": ["<rootDir>/src/nestjs/$1"],
7+
"^test/(.*)$": ["<rootDir>/src/test/$1"]
8+
},
119
"rootDir": "./src",
1210
"testRegex": ".spec.ts$",
1311
"transform": {
1412
"^.+\\.(t|j)s$": "ts-jest"
1513
},
1614
"restoreMocks": true,
1715
"resetMocks": true
18-
}
16+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
"build:package": "yarn tsc --declaration --project tsconfig.build.json",
1212
"build:replace-tspaths": "yarn tscpaths -p tsconfig.build.json -s ./src -o ./dist",
1313
"build": "rimraf dist && yarn build:package && yarn build:replace-tspaths",
14-
"test": "jest --config=./jest.config.json"
14+
"test": "jest --config=./jest.config.json",
15+
"generate:random-data": "yarn ts-node ./src/test/scripts/generate-random-data.ts"
1516
},
1617
"keywords": [
1718
"nestjs",
1819
"pgds-common"
1920
],
2021
"dependencies": {
2122
"@elastic/elasticsearch": "7.13.0",
23+
"@faker-js/faker": "^8.1.0",
2224
"@nestjs/common": "10.2.6",
2325
"@nestjs/elasticsearch": "9.0.0",
2426
"class-validator": "0.14.0",
@@ -51,6 +53,7 @@
5153
"prettier": "3.0.3",
5254
"rimraf": "5.0.1",
5355
"ts-jest": "29.1.1",
56+
"ts-node": "10.9.1",
5457
"tscpaths": "0.0.9",
5558
"typescript": "5.2.2"
5659
},
@@ -61,4 +64,4 @@
6164
"publishConfig": {
6265
"@propertyguru:registry": "https://npm.pkg.github.com/propertyguru"
6366
}
64-
}
67+
}

src/lib/aggregations/get-avg.spec.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import { describe } from 'node:test'
2-
import { ExampleCatalogDocument } from 'test/module'
1+
import { HomeDocument } from 'test/module'
32
import { getAvgAggregation } from './get-avg'
43

54
describe('getAvgAggregation', () => {
6-
it('accepts only schema fields', () => {
7-
const query = getAvgAggregation<ExampleCatalogDocument>('field')
5+
it('accepts only schema field', () => {
6+
const query = getAvgAggregation<HomeDocument>('address')
87

98
expect(query).toEqual({
109
avg: {
11-
field: 'field'
10+
field: 'address'
1211
}
1312
})
1413
})
1514

16-
it('accepts only schema fields with keyword', () => {
17-
const query = getAvgAggregation<ExampleCatalogDocument>('field.keyword')
15+
it('accepts only schema field with keyword', () => {
16+
const query = getAvgAggregation<HomeDocument>('address.keyword')
1817

1918
expect(query).toEqual({
2019
avg: {
21-
field: 'field.keyword'
20+
field: 'address.keyword'
2221
}
2322
})
2423
})

src/lib/aggregations/get-sum.spec.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import { describe } from 'node:test'
2-
import { ExampleCatalogDocument } from 'test/module'
1+
import { HomeDocument } from 'test/module'
32
import { getSumAggregation } from './get-sum'
43

54
describe('getSumAggregation', () => {
6-
it('accepts only schema fields', () => {
7-
const query = getSumAggregation<ExampleCatalogDocument>('field')
5+
it('accepts only schema field', () => {
6+
const query = getSumAggregation<HomeDocument>('address')
87

98
expect(query).toEqual({
109
sum: {
11-
field: 'field'
10+
field: 'address'
1211
}
1312
})
1413
})
1514

16-
it('accepts only schema fields with keyword', () => {
17-
const query = getSumAggregation<ExampleCatalogDocument>('field.keyword')
15+
it('accepts only schema field with keyword', () => {
16+
const query = getSumAggregation<HomeDocument>('address.keyword')
1817

1918
expect(query).toEqual({
2019
sum: {
21-
field: 'field.keyword'
20+
field: 'address.keyword'
2221
}
2322
})
2423
})

src/lib/queries/get-bool-should.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/lib/queries/get-bool.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
describe('getBoolQuery', () => {
2+
test.todo('accepts optional must query')
3+
test.todo('accepts optional should query')
4+
})

src/lib/queries/get-bool.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Document } from 'lib/types'
2-
import { getBoolMustQuery } from './get-bool-must'
3-
import { getBoolShouldQuery } from './get-bool-should'
2+
import { getMustQuery } from './get-must'
3+
import { getShouldQuery } from './get-should'
44

55
export type BoolQuery<TDocument extends Document> = {
6-
must?: ReturnType<typeof getBoolMustQuery<TDocument>>
7-
should?: ReturnType<typeof getBoolShouldQuery<TDocument>>
6+
must?: ReturnType<typeof getMustQuery<TDocument>>
7+
should?: ReturnType<typeof getShouldQuery<TDocument>>
88
}
99

1010
export const getBoolQuery = <TDocument extends Document>(bool: BoolQuery<TDocument>) => ({

src/lib/queries/get-must.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
describe('getMustQuery', () => {
2+
test.todo('accepts optional term query')
3+
test.todo('accepts optional terms query')
4+
})

src/lib/queries/get-bool-must.ts renamed to src/lib/queries/get-must.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Document } from 'lib/types'
22
import { getTermQuery } from './get-term'
33
import { getTermsQuery } from './get-terms'
44

5-
export type BoolMustQuery<TDocument extends Document> = {
5+
export type MustQuery<TDocument extends Document> = {
66
term?: ReturnType<typeof getTermQuery<TDocument>>
77
terms?: ReturnType<typeof getTermsQuery<TDocument>>
88
}
99

10-
export const getBoolMustQuery = <TDocument extends Document>(query: BoolMustQuery<TDocument> | Array<BoolMustQuery<TDocument>>) => query
10+
export const getMustQuery = <TDocument extends Document>(query: MustQuery<TDocument> | Array<MustQuery<TDocument>>) => query

src/lib/queries/get-should.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
describe('getShouldQuery', () => {
2+
test.todo('accepts optional term query')
3+
test.todo('accepts optional terms query')
4+
})

0 commit comments

Comments
 (0)