Skip to content

Commit

Permalink
Removing commented-out method and test for asserting log links to pre…
Browse files Browse the repository at this point in the history
…vious state
  • Loading branch information
mzkrasner committed Dec 12, 2024
1 parent 38a90f5 commit 6452ab5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 77 deletions.
36 changes: 0 additions & 36 deletions packages/model-instance-handler/src/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,39 +133,3 @@ export function assertValidUniqueValue(
)
}
}

/**
* Asserts that the 'id' and 'prev' properties of the given event properly link to the tip of
* the given document state.
*
* By the time the code gets into a StreamtypeHandler's applyCommit function the link to the state
* should already have been established by the stream loading and conflict resolution code, so
* if this check were to fail as part of a StreamtypeHandler's applyCommit function, that would
* indicate a programming error.
*/
// export function assertEventLinksToState(
// payload: DocumentDataEventPayload | TimeEvent,
// state: DocumentState,
// ) {
// if (state.log.length === 0) {
// throw new Error('Invalid document state: log is empty')
// }

// const initCID = state.log[0]

// // Older versions of the CAS created time events without an 'id' field, so only check
// // the event payload 'id' field if it is present.
// if (payload.id != null && payload.id.toString() !== initCID) {
// throw new Error(
// `Invalid init CID in event payload for document, expected ${initCID} but got ${payload.id}`,
// )
// }

// const prev = payload.prev.toString()
// const expectedPrev = state.log[state.log.length - 1]
// if (prev !== expectedPrev) {
// throw new Error(
// `Commit doesn't properly point to previous event payload in log for document ${initCID}. Expected ${expectedPrev}, found 'prev' ${prev}`,
// )
// }
// }
41 changes: 0 additions & 41 deletions packages/model-instance-handler/test/assertions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,6 @@ import {
import type { DocumentState } from '../src/types.js'
import { encodeUniqueFieldsValue } from '../src/utils.js'

// describe('assertEventLinksToState()', () => {
// test('throws if the state log is empty', () => {
// const cid = randomCID()
// expect(() => {
// assertEventLinksToState(
// { id: cid } as unknown as DocumentDataEventPayload,
// { log: [] } as unknown as DocumentState,
// )
// }).toThrow('Invalid document state: log is empty')
// })

// test('throws if the event id does not match the init event cid', () => {
// const expectedID = randomCID().toString()
// const invalidID = randomCID()
// expect(() => {
// assertEventLinksToState(
// { id: invalidID } as unknown as DocumentDataEventPayload,
// { log: [expectedID] } as unknown as DocumentState,
// )
// }).toThrow(
// `Invalid init CID in event payload for document, expected ${expectedID} but got ${invalidID}`,
// )
// })

// test('throws if the event prev does not match the previous event cid', () => {
// const initID = randomCID()
// const expectedID = randomCID()
// const invalidID = randomCID()
// expect(() => {
// assertEventLinksToState(
// { id: initID, prev: invalidID } as unknown as DocumentDataEventPayload,
// {
// log: [initID.toString(), expectedID.toString()],
// } as unknown as DocumentState,
// )
// }).toThrow(
// `Commit doesn't properly point to previous event payload in log for document ${initID}. Expected ${expectedID}, found 'prev' ${invalidID}`,
// )
// })
// })

describe('assertNoImmutableFieldChange()', () => {
test('throws if an immutable field is changed', () => {
expect(() => {
Expand Down

0 comments on commit 6452ab5

Please sign in to comment.