-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Add Integration support (#203)
- Loading branch information
Showing
28 changed files
with
9,433 additions
and
6,083 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
import { AlphanumericReasonValidationPipe } from './alphanumeric-reason-pipe'; | ||
import { BadRequestException } from '@nestjs/common'; | ||
import { AlphanumericReasonValidationPipe } from './alphanumeric-reason-pipe' | ||
import { BadRequestException } from '@nestjs/common' | ||
|
||
describe('AlphanumericReasonValidationPipe', () => { | ||
let pipe: AlphanumericReasonValidationPipe; | ||
let pipe: AlphanumericReasonValidationPipe | ||
|
||
beforeEach(() => { | ||
pipe = new AlphanumericReasonValidationPipe(); | ||
}); | ||
pipe = new AlphanumericReasonValidationPipe() | ||
}) | ||
|
||
it('should allow alphanumeric string', () => { | ||
const validInput = 'Test123'; | ||
expect(pipe.transform(validInput)).toBe(validInput); | ||
}); | ||
const validInput = 'Test123' | ||
expect(pipe.transform(validInput)).toBe(validInput) | ||
}) | ||
|
||
it('should not allow strings with only spaces', () => { | ||
expect(() => pipe.transform(' ')).toThrow(BadRequestException); | ||
}); | ||
expect(() => pipe.transform(' ')).toThrow(BadRequestException) | ||
}) | ||
|
||
it('should throw BadRequestException for non-alphanumeric string', () => { | ||
const invalidInput = 'Test123$%^'; | ||
const invalidInput = 'Test123$%^' | ||
try { | ||
pipe.transform(invalidInput); | ||
pipe.transform(invalidInput) | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(BadRequestException); | ||
expect(e.message).toBe('Reason must contain only alphanumeric characters and no leading or trailing spaces.'); | ||
expect(e).toBeInstanceOf(BadRequestException) | ||
expect(e.message).toBe( | ||
'Reason must contain only alphanumeric characters and no leading or trailing spaces.' | ||
) | ||
} | ||
}); | ||
}); | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { PipeTransform, Injectable, BadRequestException } from '@nestjs/common'; | ||
import { PipeTransform, Injectable, BadRequestException } from '@nestjs/common' | ||
|
||
@Injectable() | ||
export class AlphanumericReasonValidationPipe implements PipeTransform { | ||
transform(value: string) { | ||
if (/^[a-zA-Z0-9]+(?: [a-zA-Z0-9]+)*$/.test(value)) { | ||
return value; | ||
} else { | ||
throw new BadRequestException('Reason must contain only alphanumeric characters and no leading or trailing spaces.'); | ||
if (/^[a-zA-Z0-9]+(?: [a-zA-Z0-9]+)*$/.test(value)) { | ||
return value | ||
} else { | ||
throw new BadRequestException( | ||
'Reason must contain only alphanumeric characters and no leading or trailing spaces.' | ||
) | ||
} | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
apps/api/src/integration/controller/integration.controller.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,28 @@ | ||
import { Test, TestingModule } from '@nestjs/testing' | ||
import { IntegrationController } from './integration.controller' | ||
import { PrismaService } from '../../prisma/prisma.service' | ||
import { mockDeep } from 'jest-mock-extended' | ||
import { AuthorityCheckerService } from '../../common/authority-checker.service' | ||
import { IntegrationService } from '../service/integration.service' | ||
import { CommonModule } from '../../common/common.module' | ||
|
||
describe('IntegrationController', () => { | ||
let controller: IntegrationController | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [CommonModule], | ||
controllers: [IntegrationController], | ||
providers: [PrismaService, AuthorityCheckerService, IntegrationService] | ||
}) | ||
.overrideProvider(PrismaService) | ||
.useValue(mockDeep<PrismaService>()) | ||
.compile() | ||
|
||
controller = module.get<IntegrationController>(IntegrationController) | ||
}) | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined() | ||
}) | ||
}) |
Oops, something went wrong.