First commit
This commit is contained in:
53
backend/test/cards.test.ts
Normal file
53
backend/test/cards.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import type { Card } from '../src/cards.js'
|
||||
import { matchesCardFilters } from '../src/cards.js'
|
||||
|
||||
function card(overrides: Partial<Card> = {}): Card {
|
||||
return {
|
||||
oracle_id: 'test',
|
||||
name: 'Test Card',
|
||||
layout: 'normal',
|
||||
cmc: 3,
|
||||
type_line: 'Legendary Creature — Human',
|
||||
colors: ['G', 'U'],
|
||||
color_identity: ['G', 'U'],
|
||||
keywords: [],
|
||||
rarity: 'rare',
|
||||
legal_formats: ['commander', 'legacy'],
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
const cardByIdentity = card({ color_identity: ['G', 'U'] })
|
||||
|
||||
test('card filters match format legality, color identity, type, rarity, and mana value', () => {
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { format: 'legacy' }), true)
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { format: 'standard' }), false)
|
||||
assert.equal(matchesCardFilters(cardByIdentity, {}), true)
|
||||
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { color: 'U' }), true)
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { color: 'M' }), true)
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { color: 'C' }), false)
|
||||
assert.equal(matchesCardFilters(card({ color_identity: [] }), { color: 'C' }), true)
|
||||
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { type: 'legendary' }), true)
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { type: 'creature' }), true)
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { type: 'land' }), false)
|
||||
|
||||
const modalCard = card({
|
||||
type_line: 'Sorcery',
|
||||
card_faces: [
|
||||
{ name: 'Front', type_line: 'Sorcery', colors: [] },
|
||||
{ name: 'Back', type_line: 'Land', colors: [] },
|
||||
],
|
||||
})
|
||||
assert.equal(matchesCardFilters(modalCard, { type: 'land' }), true)
|
||||
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { rarity: 'rare' }), true)
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { rarity: 'common' }), false)
|
||||
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { cmcMin: 3, cmcMax: 3 }), true)
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { cmcMin: 4 }), false)
|
||||
assert.equal(matchesCardFilters(cardByIdentity, { cmcMax: 2 }), false)
|
||||
})
|
||||
Reference in New Issue
Block a user