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
36
37
38
39
40
41
|
// bun test names/migrate-check.test.js
import { test, expect } from 'bun:test';
import { migrateGrantRefusal, FRESH_MS } from './migrate-check.js';
const NOW = 1_800_000_000_000;
const coinos = (users, status) => async (url) => {
const name = decodeURIComponent(url.split('/').pop());
if (status) return new Response('', { status });
const u = users[name.toLowerCase()];
return u ? Response.json(u) : new Response('{}', { status: 404 });
};
const users = {
alice: { username: 'Alice', migrated: true, v3migrated: NOW - 5_000 },
// every account created since 2023 carries migrated: true; it proves nothing
victim: { username: 'victim', migrated: true },
bob: { username: 'bob' },
stale: { username: 'stale', migrated: true, v3migrated: NOW - FRESH_MS - 1 },
future: { username: 'future', v3migrated: NOW + 10 * 60_000 },
junk: { username: 'junk', v3migrated: 'yes' },
};
const refusal = (n, f = coinos(users)) => migrateGrantRefusal(n, f, NOW);
test('an account that just handed itself over may hand its name over', async () => {
expect(await refusal('alice')).toBeNull();
});
test('the legacy `migrated` flag alone is not enough', async () => {
expect((await refusal('victim'))[0]).toBe(409);
expect((await refusal('bob'))[0]).toBe(409);
});
test('a hand-off that is stale, from the future, or not a timestamp is refused', async () => {
expect((await refusal('stale'))[0]).toBe(409);
expect((await refusal('future'))[0]).toBe(409);
expect((await refusal('junk'))[0]).toBe(409);
});
test('a name with no coinos.io account is refused', async () => {
expect((await refusal('nobody'))[0]).toBe(404);
});
test("coinos.io down means no grant, and it says to try again", async () => {
expect((await refusal('alice', coinos(users, 502)))[0]).toBe(502);
expect((await refusal('alice', async () => { throw new Error('net'); }))[0]).toBe(502);
});
|