Cover consumed adoption transfer codes
This commit is contained in:
@@ -6,7 +6,10 @@ import {
|
||||
createBird,
|
||||
createPendingBirdTransfer,
|
||||
getBirdById,
|
||||
getOpenBirdTransferCode,
|
||||
getOpenBirdTransferCodeForBird,
|
||||
listWeightsForBird,
|
||||
markBirdTransferCodeCompleted,
|
||||
transferBirdToWorkspace,
|
||||
} from './birdRepository.js';
|
||||
import { mockDb } from '../test/mockDb.js';
|
||||
@@ -198,3 +201,36 @@ test('completePendingBirdTransfersForOwner moves pending birds and marks complet
|
||||
assert.deepEqual(calls[2].params, ['transfer-1', 22]);
|
||||
assert.match(calls[2].text, /completed_at = CURRENT_TIMESTAMP/);
|
||||
});
|
||||
|
||||
test('getOpenBirdTransferCode only returns unconsumed codes', async () => {
|
||||
const { calls } = mockDb({ rowCount: 0, rows: [] });
|
||||
|
||||
const transferCode = await getOpenBirdTransferCode('ADOPT-123');
|
||||
|
||||
assert.equal(transferCode, null);
|
||||
assert.deepEqual(calls[0].params, ['ADOPT-123']);
|
||||
assert.match(calls[0].text, /bird_transfer_codes\.completed_at IS NULL/);
|
||||
assert.match(calls[0].text, /bird_transfer_codes\.revoked_at IS NULL/);
|
||||
assert.match(calls[0].text, /birds\.workspace_id = bird_transfer_codes\.source_workspace_id/);
|
||||
});
|
||||
|
||||
test('getOpenBirdTransferCodeForBird ignores consumed codes', async () => {
|
||||
const { calls } = mockDb({ rowCount: 0, rows: [] });
|
||||
|
||||
const transferCode = await getOpenBirdTransferCodeForBird('bird-1', 10);
|
||||
|
||||
assert.equal(transferCode, null);
|
||||
assert.deepEqual(calls[0].params, ['bird-1', 10]);
|
||||
assert.match(calls[0].text, /completed_at IS NULL/);
|
||||
assert.match(calls[0].text, /revoked_at IS NULL/);
|
||||
});
|
||||
|
||||
test('markBirdTransferCodeCompleted consumes a code for the receiving workspace', async () => {
|
||||
const { calls } = mockDb({ rowCount: 1, rows: [] });
|
||||
|
||||
await markBirdTransferCodeCompleted('code-1', 22);
|
||||
|
||||
assert.deepEqual(calls[0].params, ['code-1', 22]);
|
||||
assert.match(calls[0].text, /SET completed_at = CURRENT_TIMESTAMP/);
|
||||
assert.match(calls[0].text, /completed_workspace_id = \$2/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user