Skip to content

Commit

Permalink
only add wealth field if it's defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Aug 1, 2024
1 parent 74ef539 commit 771e32c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/api/squaremap/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ export const parseNations = async(towns: SquaremapTown[]) => {
councillors: [],
towns: [],
area: 0,
wealth: 0,
king: undefined,
capital: undefined
}
Expand All @@ -257,7 +256,9 @@ export const parseNations = async(towns: SquaremapTown[]) => {
raw[nationName].councillors = fastMergeUnique(raw[nationName].councillors, town.councillors)

raw[nationName].area += town.area
raw[nationName].wealth += town.wealth

if (town.wealth)
raw[nationName].wealth += town.wealth

// Current town is in existing nation
if (raw[nationName].name == nationName)
Expand Down
2 changes: 1 addition & 1 deletion src/types/nation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type BaseNation = {

export type Nation = Prettify<BaseNation & Partial<APINationInfo>>
export type SquaremapNation = Prettify<Nation & {
wealth: number
wealth?: number
councillors: string[]
}>

Expand Down
11 changes: 7 additions & 4 deletions tests/squaremap/nations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it, expect, expectTypeOf, assertType } from 'vitest'

import type { SquaremapNation } from '../../src/types'

import { Aurora } from '../../src/main'
import { Aurora, NotFoundError } from '../../src/main'

describe('[Squaremap/Aurora] Nations', () => {
let nations: SquaremapNation[] = null
Expand All @@ -29,11 +29,14 @@ describe('[Squaremap/Aurora] Nations', () => {
expect(nation.name).toBe('R.O.C')
})

it('can get multiple nation', async () => {
const nations = await Aurora.Nations.get('SiBeRia', 'veNICE', 'verMOnt', 'vAult_citY') as SquaremapNation[]
it('can get multiple nations', async () => {
const nations = await Aurora.Nations.get('SiBeRia', 'veNICE', 'verMOnt', 'fAroe_ISlanDs') as SquaremapNation[]

console.log(nations)

expect(nations).toBeTruthy()
expect(nations.length).toBe(3)
expect(nations.length).toBe(4)
expect(nations.some(n => n instanceof NotFoundError)).toBe(false)

assertType<SquaremapNation[]>(nations)
})
Expand Down

0 comments on commit 771e32c

Please sign in to comment.