Refine live control and show overview
This commit is contained in:
1 parent
ec596d442e
commit
b1474bc33d
16 files changed
+1580
-405
No files matched your search
@@ -70,6 +70,21 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
describe('authentication', () => {
|
||||
it('stores the show overview preference per user', async () => {
|
||||
const { createFirstAdmin, getShowOverviewView, setShowOverviewView } =
|
||||
await import('./auth.js');
|
||||
const user = await createFirstAdmin({
|
||||
setupToken: 'a'.repeat(32),
|
||||
email: 'calendar@example.test',
|
||||
displayName: 'Kalender Test',
|
||||
password: 'a-valid-password-123'
|
||||
});
|
||||
expect(getShowOverviewView(user.id)).toBe('list');
|
||||
expect(setShowOverviewView(user.id, 'calendar')).toBe('calendar');
|
||||
expect(getShowOverviewView(user.id)).toBe('calendar');
|
||||
expect(() => setShowOverviewView(user.id, 'invalid')).toThrow('INVALID_VIEW');
|
||||
});
|
||||
|
||||
it('creates the first Barkeeper once and stores no plaintext secret', async () => {
|
||||
const { createFirstAdmin } = await import('./auth.js');
|
||||
const password = 'Ein-sehr-langes-Testpasswort';
|
||||
|
||||
@@ -26,6 +26,7 @@ const PASSWORD_OPTIONS = {
|
||||
} as const;
|
||||
|
||||
export type Role = 'barkeeper' | 'thekencrew';
|
||||
export type ShowOverviewView = 'list' | 'calendar';
|
||||
export type AuthUser = {
|
||||
id: string;
|
||||
email: string;
|
||||
@@ -66,6 +67,23 @@ export function normalizeEmail(email: string): string {
|
||||
return email.trim().toLowerCase();
|
||||
}
|
||||
|
||||
export function getShowOverviewView(userId: string): ShowOverviewView {
|
||||
const row = getDatabase()
|
||||
.prepare('SELECT show_overview_view FROM users WHERE id = ?')
|
||||
.get(userId) as { show_overview_view: ShowOverviewView } | undefined;
|
||||
if (!row) throw new Error('NOT_FOUND');
|
||||
return row.show_overview_view;
|
||||
}
|
||||
|
||||
export function setShowOverviewView(userId: string, view: string): ShowOverviewView {
|
||||
if (view !== 'list' && view !== 'calendar') throw new Error('INVALID_VIEW');
|
||||
const result = getDatabase()
|
||||
.prepare('UPDATE users SET show_overview_view = ?, updated_at_utc = ? WHERE id = ?')
|
||||
.run(view, nowUtc(), userId);
|
||||
if (!result.changes) throw new Error('NOT_FOUND');
|
||||
return view;
|
||||
}
|
||||
|
||||
export function validEmail(email: string): boolean {
|
||||
return email.length <= 254 && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ describe('database setup', () => {
|
||||
database.close();
|
||||
|
||||
expect(counts).toEqual({
|
||||
migrations: 11,
|
||||
migrations: 12,
|
||||
pieces: 6,
|
||||
shows: 2,
|
||||
usages: 5,
|
||||
|
||||
Reference in new issue
Block a user