Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Added tests for template-attachment functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgtho committed Nov 30, 2021
1 parent 48f6a31 commit 7674e6f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/create-metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ const data = {
}
}

const dataWithAttachment = {
template: {
service: 'DocumentService',
method: 'CreateDocument',
parameter: {
ReferenceNumber: '<<<organizationNumber>>>'
}
},
documentData: {
organizationNumber: '01234',
school: {
organizationNumber: '56789'
},
attachments: [{
title: 'Et vedlegg',
format: 'docx',
base64: 'blablabla'
}]
}
}

test('Exception thrown when "template" is not defined', () => {
const fn = () => createMetadata({})
expect(fn).toThrow(HTTPError)
Expand Down Expand Up @@ -43,6 +64,29 @@ test('Exception thrown when object token doesn\'t exist', () => {
expect(fn).toThrow(HTTPError)
})

test('Attachment is added to metadata, if attachments parameter is defined', () => {
const metadata = createMetadata(dataWithAttachment)
expect(metadata.parameter.Files[0].Title).toBe(dataWithAttachment.documentData.attachments[0].title)
})

test('Exception thrown when attachment is missing required property', () => {
delete dataWithAttachment.documentData.attachments[0].title
const fn = () => createMetadata(dataWithAttachment)
expect(fn).toThrow(HTTPError)
dataWithAttachment.documentData.attachments[0].title = 'Tittel er tilbake'
})

test('Attachments are added to metadata, if attachments parameter is defined with several files', () => {
dataWithAttachment.documentData.attachments.push({
title: 'Vedlegg 2',
format: 'pdf',
base64: 'tuuukkkl'
})
console.log(dataWithAttachment.documentData.attachments[1])
const metadata = createMetadata(dataWithAttachment)
expect(metadata.parameter.Files.length).toBe(2)
})

const templates = readdirSync('./templates') // outside the test working dir is root foler
describe('Test templates', () => {
test.each(templates)('Expect template %p to have an "archive" property', template => {
Expand Down

0 comments on commit 7674e6f

Please sign in to comment.