-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): CoingeckoCoinsId zod (#3329)
# Motivation Zod for `CoingeckoCoinsId`. # Notes I just convert the type I need for the PR / task I'm working on in #3326 and not all the Coingecko types.
- Loading branch information
1 parent
731006d
commit 15de402
Showing
3 changed files
with
45 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { z } from 'zod'; | ||
|
||
export const CoingeckoCoinsIdSchema = z.enum(['ethereum', 'bitcoin', 'internet-computer']); |
39 changes: 39 additions & 0 deletions
39
src/frontend/src/tests/lib/validation/coingecko.validation.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,39 @@ | ||
import { CoingeckoCoinsIdSchema } from '$lib/validation/coingecko.validation'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
describe('CoingeckoCoinsIdSchema', () => { | ||
it('should pass validation for "ethereum"', () => { | ||
const validData = 'ethereum'; | ||
expect(CoingeckoCoinsIdSchema.parse(validData)).toEqual(validData); | ||
}); | ||
|
||
it('should pass validation for "bitcoin"', () => { | ||
const validData = 'bitcoin'; | ||
expect(CoingeckoCoinsIdSchema.parse(validData)).toEqual(validData); | ||
}); | ||
|
||
it('should pass validation for "internet-computer"', () => { | ||
const validData = 'internet-computer'; | ||
expect(CoingeckoCoinsIdSchema.parse(validData)).toEqual(validData); | ||
}); | ||
|
||
it('should fail validation for an unsupported coin ID', () => { | ||
const invalidData = 'dogecoin'; | ||
expect(() => CoingeckoCoinsIdSchema.parse(invalidData)).toThrow(); | ||
}); | ||
|
||
it('should fail validation for a number instead of a string', () => { | ||
const invalidData = 123; | ||
expect(() => CoingeckoCoinsIdSchema.parse(invalidData)).toThrow(); | ||
}); | ||
|
||
it('should fail validation for null', () => { | ||
const invalidData = null; | ||
expect(() => CoingeckoCoinsIdSchema.parse(invalidData)).toThrow(); | ||
}); | ||
|
||
it('should fail validation for undefined', () => { | ||
const invalidData = undefined; | ||
expect(() => CoingeckoCoinsIdSchema.parse(invalidData)).toThrow(); | ||
}); | ||
}); |