Files
gridpilot.gg/apps/api/src/domain/payments/presenters/UpsertMembershipFeePresenter.test.ts
Marc Mintel fb1221701d
Some checks failed
Contract Testing / contract-tests (push) Failing after 6m7s
Contract Testing / contract-snapshot (push) Failing after 4m46s
add tests
2026-01-22 11:52:42 +01:00

183 lines
4.9 KiB
TypeScript

import { UpsertMembershipFeePresenter } from './UpsertMembershipFeePresenter';
import { UpsertMembershipFeeResultDTO } from '../dtos/UpsertMembershipFeeDTO';
import { MembershipFeeType } from '../dtos/MembershipFeeType';
describe('UpsertMembershipFeePresenter', () => {
let presenter: UpsertMembershipFeePresenter;
beforeEach(() => {
presenter = new UpsertMembershipFeePresenter();
});
describe('present', () => {
it('should store the result', () => {
const result: UpsertMembershipFeeResultDTO = {
fee: {
id: 'fee-123',
leagueId: 'league-123',
type: MembershipFeeType.MONTHLY,
amount: 100,
enabled: true,
createdAt: new Date('2024-01-01'),
updatedAt: new Date('2024-01-02'),
},
};
presenter.present(result);
expect(presenter.getResponseModel()).toEqual(result);
});
it('should overwrite previous result', () => {
const firstResult: UpsertMembershipFeeResultDTO = {
fee: {
id: 'fee-123',
leagueId: 'league-123',
type: MembershipFeeType.MONTHLY,
amount: 100,
enabled: true,
createdAt: new Date('2024-01-01'),
updatedAt: new Date('2024-01-02'),
},
};
const secondResult: UpsertMembershipFeeResultDTO = {
fee: {
id: 'fee-456',
leagueId: 'league-456',
type: MembershipFeeType.SEASON,
amount: 200,
enabled: false,
createdAt: new Date('2024-01-03'),
updatedAt: new Date('2024-01-04'),
},
};
presenter.present(firstResult);
presenter.present(secondResult);
expect(presenter.getResponseModel()).toEqual(secondResult);
});
});
describe('getResponseModel', () => {
it('should return null when not presented', () => {
expect(presenter.getResponseModel()).toBeNull();
});
it('should return the result after present()', () => {
const result: UpsertMembershipFeeResultDTO = {
fee: {
id: 'fee-123',
leagueId: 'league-123',
type: MembershipFeeType.MONTHLY,
amount: 100,
enabled: true,
createdAt: new Date('2024-01-01'),
updatedAt: new Date('2024-01-02'),
},
};
presenter.present(result);
expect(presenter.getResponseModel()).toEqual(result);
});
});
describe('reset', () => {
it('should clear the result', () => {
const result: UpsertMembershipFeeResultDTO = {
fee: {
id: 'fee-123',
leagueId: 'league-123',
type: MembershipFeeType.MONTHLY,
amount: 100,
enabled: true,
createdAt: new Date('2024-01-01'),
updatedAt: new Date('2024-01-02'),
},
};
presenter.present(result);
presenter.reset();
expect(presenter.getResponseModel()).toBeNull();
});
it('should allow presenting again after reset', () => {
const firstResult: UpsertMembershipFeeResultDTO = {
fee: {
id: 'fee-123',
leagueId: 'league-123',
type: MembershipFeeType.MONTHLY,
amount: 100,
enabled: true,
createdAt: new Date('2024-01-01'),
updatedAt: new Date('2024-01-02'),
},
};
const secondResult: UpsertMembershipFeeResultDTO = {
fee: {
id: 'fee-456',
leagueId: 'league-456',
type: MembershipFeeType.SEASON,
amount: 200,
enabled: false,
createdAt: new Date('2024-01-03'),
updatedAt: new Date('2024-01-04'),
},
};
presenter.present(firstResult);
presenter.reset();
presenter.present(secondResult);
expect(presenter.getResponseModel()).toEqual(secondResult);
});
});
describe('viewModel', () => {
it('should return the result', () => {
const result: UpsertMembershipFeeResultDTO = {
fee: {
id: 'fee-123',
leagueId: 'league-123',
type: MembershipFeeType.MONTHLY,
amount: 100,
enabled: true,
createdAt: new Date('2024-01-01'),
updatedAt: new Date('2024-01-02'),
},
};
presenter.present(result);
expect(presenter.viewModel).toEqual(result);
});
it('should throw error when accessed before present()', () => {
expect(() => presenter.viewModel).toThrow('Presenter not presented');
});
it('should throw error after reset', () => {
const result: UpsertMembershipFeeResultDTO = {
fee: {
id: 'fee-123',
leagueId: 'league-123',
type: MembershipFeeType.MONTHLY,
amount: 100,
enabled: true,
createdAt: new Date('2024-01-01'),
updatedAt: new Date('2024-01-02'),
},
};
presenter.present(result);
presenter.reset();
expect(() => presenter.viewModel).toThrow('Presenter not presented');
});
});
});