Skip to content

Commit

Permalink
feat(api): add passage-event-repository with record method
Browse files Browse the repository at this point in the history
Co-authored-by: Diane Cordier <[email protected]>
Co-authored-by: Eric Lim <[email protected]>
  • Loading branch information
3 people committed Mar 4, 2025
1 parent 7ac58f7 commit 6fa4644
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DomainTransaction } from '../../../shared/domain/DomainTransaction.js';

async function record(event) {
const knexConn = DomainTransaction.getConnection();
await knexConn('passage-events').insert({
passageId: event.passageId,
occurredAt: event.occurredAt,
type: event.type,
data: event.data,
});
}

export { record };
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { PassageStartedEvent } from '../../../../src/devcomp/domain/models/passage-events/passage-events.js';
import * as passageEventRepository from '../../../../src/devcomp/infrastructure/repositories/passage-event-repository.js';
import { databaseBuilder, expect, knex, sinon } from '../../../test-helper.js';

describe('Integration | DevComp | Repositories | PassageEventRepository', function () {
describe('#record', function () {
let clock;

beforeEach(function () {
clock = sinon.useFakeTimers(new Date('2023-12-31'), 'Date');
});

afterEach(function () {
clock.restore();
});

it('should record a passage event', async function () {
// given
const passage = databaseBuilder.factory.buildPassage();
await databaseBuilder.commit();
const event = new PassageStartedEvent({
occurredAt: new Date('2019-04-28'),
passageId: passage.id,
contentHash: 'abcd1234',
});

// when
await passageEventRepository.record(event);

// then
const recordedEvent = await knex('passage-events')
.where({ type: 'PASSAGE_STARTED', passageId: passage.id })
.first();
expect(recordedEvent.data.contentHash).to.equal('abcd1234');
expect(recordedEvent.occurredAt).to.deep.equal(new Date('2019-04-28'));
});
});
});

0 comments on commit 6fa4644

Please sign in to comment.