Skip to content

Commit

Permalink
invalid car file produces isLeft; cannot decode throws error
Browse files Browse the repository at this point in the history
  • Loading branch information
gvelez17 committed Sep 11, 2023
1 parent 11cd8ad commit 95bce98
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/ancillary/__tests__/anchor-request-params-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ const CAR_FILE_INVALID = mockRequest({
})


const CAR_FILE_NOT_BASE64URL = mockRequest({
headers: {
'Content-Type': 'application/vnd.ipld.car',
},
body: '----------------------------------------',
})


const CAR_FILE_FAKE_GENESIS_FIELDS: GenesisFields = {
controllers: [asDIDString('did:pkh:eip155:1:0x926eeb192c18b7be607a7e10c8e7a7e8d9f70742')],
model: StreamID.fromBytes(
Expand Down Expand Up @@ -128,9 +136,12 @@ describe('AnchoRequestParamsParser', () => {
expect(params.capCID).toEqual(FAKE_CAPCID)
})

test('throws error on invalid car file', () => {
test('isleft indicates invalid car file', () => {
const validation = parser.parse(CAR_FILE_INVALID as ExpReq)
console.log("Here is invalid validation: " + JSON.stringify(validation))
expect(() => parser.parse(CAR_FILE_INVALID as ExpReq)).toThrow(/^Can not decode CAR file/);
expect(isLeft(validation)).toBeTruthy()
})

test('throws error if cannot decode car file', () => {
expect(() => parser.parse(CAR_FILE_NOT_BASE64URL as ExpReq)).toThrow(/^Can not decode CAR file/);
})
})

0 comments on commit 95bce98

Please sign in to comment.