Skip to content

Commit

Permalink
why can a town name have fucking brackets??
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Jul 31, 2024
1 parent b0a2f94 commit 50f1701
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/api/squaremap/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export const parsePopup = (popup: string): ParsedPopup => {

const updatedPopup = popup.replace(/<span[^>]*>.*?<\/span>/, '<b>')
const cleaned = striptags(updatedPopup.replaceAll('\n', ''), ['a']).trim()

// Keeping here in-case we should revert from regex.
//const info = cleaned.split(/\s{2,}/)

const townWiki = spanContent.match(/<a href="(.*)">(.*)<\/a> /)
Expand All @@ -85,8 +87,9 @@ export const parsePopup = (popup: string): ParsedPopup => {

const residentsMatch = sectioned.match(/Residents: .*?\/\/(.*?)(?=\/\/|$)/)
const residentsDetails = residentsMatch ? residentsMatch[1].trim() : null

const bracketMatch = spanContent.match(/^(.*?)\s*\((.*?)\)$/)

// Matches everything before last set of brackets, and everything inside last set of brackets.
const bracketMatch = spanContent.match(/^(.*)\s\(([^)]+)\)$/)

//#region Extract town and nation
const townStr = bracketMatch ? bracketMatch[1].trim() : spanContent.trim()
Expand Down
2 changes: 0 additions & 2 deletions tests/oapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ describe('[v3] OfficialAPI', async () => {

it('can get valid player info', async () => {
const players = await OfficialAPI.V3.players("af77d9b5-ab5d-4714-b92e-3b191c895ee7")

console.log(players)

expect(players).toBeDefined()
assertType<OAPIResident[]>(players)
Expand Down
33 changes: 33 additions & 0 deletions tests/squaremap/gps.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, it, expect } from 'vitest'
import { Aurora } from '../../src/main'

describe('[Squaremap/Aurora] GPS', () => {
const sampleLoc = { x: -8000, z: 100 }

it('can find the safest route', async () => {
const route = await Aurora.GPS.safestRoute(sampleLoc)

expect(route).toBeDefined()
expect(route.distance).toBeGreaterThanOrEqual(0)
})

it('can find the fastest route', async () => {
const route = await Aurora.GPS.fastestRoute(sampleLoc)

expect(route).toBeDefined()
expect(route.distance).toBeGreaterThanOrEqual(0)
})

// it('can check player is online when emitting', async () => {
// const ops = await Nova.Players.online()
// expect(ops).toBeDefined()
// expect(ops).toBeTruthy()
// assertType<Player[]>(ops)

// const op = await Nova.Players.get(ops[0]['name'])
// expect(op).toBeTruthy()

// const online = await Nova.GPS.playerIsOnline(op)
// expect(online).toEqual(true)
// })
})
14 changes: 10 additions & 4 deletions tests/squaremap/nations.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { describe, it, expect, expectTypeOf, assertType } from 'vitest'

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

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

describe('[Squaremap/Aurora] Nations', () => {
let nations: SquaremapNation[] = null

it('can get all nations', async () => {
const nations = await Aurora.Nations.all()
assertType<Nation[]>(nations)
nations = await Aurora.Nations.all()
assertType<SquaremapNation[]>(nations)
})

it('has no nation with html tag in name', () => {
expect(nations.some(n => n.name.includes("</a>") || n.name.includes("<a>"))).toBe(false)
})

it('can get single nation', async () => {
Expand All @@ -17,7 +23,7 @@ describe('[Squaremap/Aurora] Nations', () => {
expectTypeOf(nation).not.toEqualTypeOf<Error>

//@ts-expect-error
assertType<Nation | Nation[]>(nation)
assertType<SquaremapNation | SquaremapNation[]>(nation)

//@ts-ignore
expect(nation.name).toBe('R.O.C')
Expand Down
8 changes: 7 additions & 1 deletion tests/squaremap/towns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ import { SquaremapTown } from '../../src/types'
import { Aurora } from '../../src/main'

describe('[Squaremap/Aurora] Towns', () => {
let towns: SquaremapTown[] = null

it('can get all towns', async () => {
const towns = await Aurora.Towns.all()
towns = await Aurora.Towns.all()
assertType<SquaremapTown[]>(towns)
})

it('has no town with html tag in name', () => {
expect(towns.some(t => t.name.includes("</a>") || t.name.includes("<a>"))).toBe(false)
})

// TODO: Verify there are no duplicates residents.
it('can get single town', async () => {
const town = await Aurora.Towns.get('Hengyang')
Expand Down

0 comments on commit 50f1701

Please sign in to comment.