garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /crates/atlas/web/src/lib/invite.test.ts

raw

import {describe, expect, test} from 'bun:test'

import {inviteCode, inviteLink} from './invite'

describe('invite links', () => {
    test('an invite link names the server that made it', () => {
        expect(inviteLink('abc123', 'https://rug.example')).toBe('https://rug.example/go?community=abc123')
        expect(inviteLink('abc123', 'https://cartopolis.org')).toBe('https://cartopolis.org/go?community=abc123')
    })

    test('an invite link from any server reads back as its code', () => {
        expect(inviteCode(inviteLink('abc123', 'https://rug.example'))).toBe('abc123')
        expect(inviteCode(' abc123 ')).toBe('abc123')
        expect(inviteCode('https://rug.example/go?place=1,2')).toBeNull()
        expect(inviteCode('../etc')).toBeNull()
    })
})