import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import test from 'node:test';

test('member store save helper does not swallow AppData save failures', () => {
  const source = readFileSync(join(process.cwd(), 'stores/useMemberStore.ts'), 'utf8');

  assert.match(
    source,
    /async function saveStored\(state: \{ departments: Department\[\]; members: Member\[\]; roles: RoleItem\[\]; passwordRule: PasswordRule \}\) \{\s+await saveServerData\('members', state\);\s+\}/,
  );
});

test('profile password form waits for member password save before showing success', () => {
  const source = readFileSync(join(process.cwd(), 'app/profile/page.tsx'), 'utf8');

  assert.match(source, /await updateMember\(user\.id, \{ password: newPwd \}\);/);
});
