-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate and only return first portfolio
- Loading branch information
Showing
4 changed files
with
67 additions
and
17 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/datasources/portfolio-api/entities/octab-get-portfolio.entity.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,33 @@ | ||
import { ZodError } from 'zod'; | ||
import { OctavGetPortfolioSchema } from '@/datasources/portfolio-api/entities/octav-get-portfolio.entity'; | ||
import type { OctavGetPortfolio } from '@/datasources/portfolio-api/entities/octav-get-portfolio.entity'; | ||
|
||
describe('OctavGetPortfolioSchema', () => { | ||
it('should validate a getPortfolio response', () => { | ||
const portfolio = { example: 'payload' }; | ||
const getPortfolio: OctavGetPortfolio = { getPortfolio: [portfolio] }; | ||
|
||
const result = OctavGetPortfolioSchema.safeParse(getPortfolio); | ||
|
||
expect(result.success).toBe(true); | ||
}); | ||
|
||
it('should not validate an invalid getPortfolio response', () => { | ||
const getPortfolio = { invalid: 'getPortfolio' }; | ||
|
||
const result = OctavGetPortfolioSchema.safeParse(getPortfolio); | ||
|
||
expect(result.success).toBe(false); | ||
expect(!result.success && result.error).toStrictEqual( | ||
new ZodError([ | ||
{ | ||
code: 'invalid_type', | ||
expected: 'array', | ||
received: 'undefined', | ||
path: ['getPortfolio'], | ||
message: 'Required', | ||
}, | ||
]), | ||
); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
src/datasources/portfolio-api/entities/octav-get-portfolio.entity.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,8 @@ | ||
import { z } from 'zod'; | ||
import { PortfolioSchema } from '@/domain/portfolio/entities/portfolio.entity'; | ||
|
||
export const OctavGetPortfolioSchema = z.object({ | ||
getPortfolio: z.array(PortfolioSchema), | ||
}); | ||
|
||
export type OctavGetPortfolio = z.infer<typeof OctavGetPortfolioSchema>; |
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