-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use prepared statements + add tests for record position (#4451)
Use prepared statements + add tests Co-authored-by: Thomas Trompette <thomast@twenty.com>
- Loading branch information
Showing
4 changed files
with
122 additions
and
41 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
64 changes: 64 additions & 0 deletions
64
.../src/workspace/workspace-query-runner/factories/__tests__/record-position.factory.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,64 @@ | ||
import { TestingModule, Test } from '@nestjs/testing'; | ||
|
||
import { WorkspaceDataSourceService } from 'src/workspace/workspace-datasource/workspace-datasource.service'; | ||
import { RecordPositionQueryFactory } from 'src/workspace/workspace-query-builder/factories/record-position-query.factory'; | ||
import { RecordPositionFactory } from 'src/workspace/workspace-query-runner/factories/record-position.factory'; | ||
|
||
describe('RecordPositionFactory', () => { | ||
const recordPositionQueryFactory = { | ||
create: jest.fn().mockResolvedValue('query'), | ||
}; | ||
|
||
const workspaceDataSourceService = { | ||
getSchemaName: jest.fn().mockReturnValue('schemaName'), | ||
executeRawQuery: jest.fn().mockResolvedValue([{ position: 1 }]), | ||
}; | ||
|
||
let factory: RecordPositionFactory; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
RecordPositionFactory, | ||
{ | ||
provide: RecordPositionQueryFactory, | ||
useValue: recordPositionQueryFactory, | ||
}, | ||
{ | ||
provide: WorkspaceDataSourceService, | ||
useValue: workspaceDataSourceService, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
factory = module.get<RecordPositionFactory>(RecordPositionFactory); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(factory).toBeDefined(); | ||
}); | ||
|
||
describe('create', () => { | ||
const objectMetadata = { isCustom: false, nameSingular: 'company' }; | ||
const workspaceId = 'workspaceId'; | ||
|
||
it('should return the value when value is a number', async () => { | ||
const value = 1; | ||
const result = await factory.create(value, objectMetadata, workspaceId); | ||
|
||
expect(result).toEqual(value); | ||
}); | ||
it('should return the existing position / 2 when value is first', async () => { | ||
const value = 'first'; | ||
const result = await factory.create(value, objectMetadata, workspaceId); | ||
|
||
expect(result).toEqual(0.5); | ||
}); | ||
it('should return the existing position + 1 when value is last', async () => { | ||
const value = 'last'; | ||
const result = await factory.create(value, objectMetadata, workspaceId); | ||
|
||
expect(result).toEqual(2); | ||
}); | ||
}); | ||
}); |
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