8b1703dce9
CI / Generate TypeScript types (push) Successful in 10s
CI / Generate TypeScript types (pull_request) Successful in 11s
CI / Server unit tests (push) Failing after 24s
CI / Build server (push) Successful in 24s
CI / Server unit tests (pull_request) Failing after 18s
CI / Build client (push) Successful in 31s
CI / Build server (pull_request) Successful in 25s
CI / Build client (pull_request) Successful in 32s
CI / Playwright E2E tests (push) Successful in 1m17s
CI / Build and push Docker image (push) Has been skipped
CI / Playwright E2E tests (pull_request) Successful in 1m9s
CI / Notify (push) Successful in 2s
CI / Build and push Docker image (pull_request) Has been skipped
CI / Notify (pull_request) Has been skipped
- odstraněn .woodpecker/workflow.yaml (CI přesunuto na Gitea Actions) - tsconfig.json: exclude src/tests/**/* (feat/tests verze) - jest.config.js: testEnvironment node + master cesty - auth/pizza/voting tests: union obou větví, použit resetMemoryStorage() - service.test.ts: jest.useFakeTimers místo MOCK_DATA=true - všechny testy: 167/167 PASS
78 lines
2.7 KiB
TypeScript
78 lines
2.7 KiB
TypeScript
import { getUserVotes, updateFeatureVote, getVotingStats } from '../voting';
|
|
import { resetMemoryStorage } from '../storage/memory';
|
|
import { FeatureRequest } from '../../../types/gen/types.gen';
|
|
|
|
const OPT_A = FeatureRequest.STATISTICS;
|
|
const OPT_B = FeatureRequest.UI;
|
|
|
|
beforeEach(() => {
|
|
resetMemoryStorage();
|
|
});
|
|
|
|
describe('updateFeatureVote', () => {
|
|
test('přidá hlas pro nového uživatele', async () => {
|
|
const result = await updateFeatureVote('alice', OPT_A, true);
|
|
expect(result['alice']).toContain(OPT_A);
|
|
});
|
|
|
|
test('vyhodí chybu při duplicitním hlasování', async () => {
|
|
await updateFeatureVote('alice', OPT_A, true);
|
|
await expect(updateFeatureVote('alice', OPT_A, true)).rejects.toThrow('hlasovali');
|
|
});
|
|
|
|
test('odebere hlas', async () => {
|
|
await updateFeatureVote('alice', OPT_A, true);
|
|
await updateFeatureVote('alice', OPT_A, false);
|
|
const stats = await getVotingStats();
|
|
expect(stats[OPT_A] ?? 0).toBe(0);
|
|
});
|
|
|
|
test('odebrání neexistujícího hlasu je no-op', async () => {
|
|
await expect(updateFeatureVote('alice', OPT_A, false)).resolves.not.toThrow();
|
|
});
|
|
|
|
test('odebrání posledního hlasu odstraní login ze storage', async () => {
|
|
await updateFeatureVote('alice', OPT_A, true);
|
|
const data = await updateFeatureVote('alice', OPT_A, false);
|
|
expect('alice' in data).toBe(false);
|
|
});
|
|
|
|
test('vyhodí chybu po 4 hlasech', async () => {
|
|
const options = Object.values(FeatureRequest);
|
|
for (let i = 0; i < 4; i++) {
|
|
await updateFeatureVote('alice', options[i], true);
|
|
}
|
|
await expect(updateFeatureVote('alice', options[4], true)).rejects.toThrow('4');
|
|
});
|
|
});
|
|
|
|
describe('getUserVotes', () => {
|
|
test('vrátí hlasy uživatele', async () => {
|
|
await updateFeatureVote('alice', OPT_A, true);
|
|
const votes = await getUserVotes('alice');
|
|
expect(votes).toContain(OPT_A);
|
|
});
|
|
|
|
test('vrátí prázdné pole pro uživatele bez hlasů', async () => {
|
|
const votes = await getUserVotes('neexistujici');
|
|
expect(votes).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('getVotingStats', () => {
|
|
test('vrátí agregované počty hlasů', async () => {
|
|
await updateFeatureVote('alice', OPT_A, true);
|
|
await updateFeatureVote('bob', OPT_A, true);
|
|
await updateFeatureVote('bob', OPT_B, true);
|
|
|
|
const stats = await getVotingStats();
|
|
expect(stats[OPT_A]).toBe(2);
|
|
expect(stats[OPT_B]).toBe(1);
|
|
});
|
|
|
|
test('vrátí prázdný objekt bez hlasů', async () => {
|
|
const stats = await getVotingStats();
|
|
expect(stats).toEqual({});
|
|
});
|
|
});
|