-
Notifications
You must be signed in to change notification settings - Fork 0
/
implementation.test.ts
35 lines (33 loc) · 1.15 KB
/
implementation.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { describe, it, expect } from 'vitest'
import { toValidFactionNameT, validateFaction } from './implementation'
import { UnvalidatedFaction } from './types'
import * as T from 'fp-ts/Task'
describe('toValidFactionName', () => {
it('should pass a name that does not exist already', async () => {
const checkFactionExists = () => T.of(false)
const factionName = 'Goliath'
const actual = await toValidFactionNameT(checkFactionExists)(factionName)()
expect(actual).toStrictEqualRight(factionName)
})
it('should reject pre-existing faction', async () => {
const checkFactionExists = () => T.of(true)
const factionName = 'Escher'
expect(
await toValidFactionNameT(checkFactionExists)(factionName)()
).toBeLeft()
})
})
describe('validateFaction', () => {
it('should pass a valid faction', async () => {
const unvalidatedFaction: UnvalidatedFaction = {
name: 'Orlock',
}
const checkFactionExists = () => T.of(false)
expect(
await validateFaction(checkFactionExists)(unvalidatedFaction)()
).toStrictEqualRight({
id: expect.any(String),
name: unvalidatedFaction.name,
})
})
})