feat: establish auth listing and image vertical slices
Includes MFA-capable authentication, session and CSRF security, password recovery, listing lifecycle and ownership rules, inventory image metadata, local ImageStorage, migrations, tests, and implementation status documentation. Verification: npm test (62 passing) and integration suite (14 passing).
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { createInitialAdminService } from '../../src/modules/auth/services/initial-admin-service.js';
|
||||
|
||||
test('provisions a normalized administrator with a linked seller', async () => {
|
||||
let provisionedInput;
|
||||
const service = createInitialAdminService({
|
||||
passwordHasher: async (password) => `hashed:${password}`,
|
||||
userRepository: {
|
||||
async createInitialAdmin(input) {
|
||||
provisionedInput = input;
|
||||
return {
|
||||
user: { id: 'user-id', email: input.email },
|
||||
seller: { id: 'seller-id' },
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const administrator = await service.provision({
|
||||
email: ' ADMIN@EXAMPLE.TEST ',
|
||||
password: 'local-password',
|
||||
sellerName: ' Catalog Owner ',
|
||||
});
|
||||
|
||||
assert.deepEqual(administrator, {
|
||||
userId: 'user-id',
|
||||
sellerId: 'seller-id',
|
||||
email: 'admin@example.test',
|
||||
});
|
||||
assert.deepEqual(provisionedInput, {
|
||||
email: 'admin@example.test',
|
||||
passwordHash: 'hashed:local-password',
|
||||
sellerName: 'Catalog Owner',
|
||||
});
|
||||
});
|
||||
|
||||
test('rejects provisioning after an administrator already exists', async () => {
|
||||
const service = createInitialAdminService({
|
||||
passwordHasher: async () => 'password-hash',
|
||||
userRepository: { async createInitialAdmin() { return null; } },
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
() =>
|
||||
service.provision({
|
||||
email: 'admin@example.test',
|
||||
password: 'local-password',
|
||||
sellerName: 'Catalog Owner',
|
||||
}),
|
||||
(error) => error.code === 'INITIAL_ADMIN_ALREADY_EXISTS',
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user