|
1 | 1 | import type { ClassValidationError } from '../../../error/ClassValidationError' |
2 | 2 |
|
| 3 | +import { Attachment } from '../../../decorators/attachment/Attachment' |
3 | 4 | import { JsonEncoder } from '../../../utils/JsonEncoder' |
4 | 5 | import { JsonTransformer } from '../../../utils/JsonTransformer' |
5 | 6 | import { OutOfBandInvitation } from '../messages/OutOfBandInvitation' |
@@ -86,6 +87,70 @@ describe('OutOfBandInvitation', () => { |
86 | 87 | expect(invitation).toBeInstanceOf(OutOfBandInvitation) |
87 | 88 | }) |
88 | 89 |
|
| 90 | + test('create an instance of `OutOfBandInvitation` from JSON object with appended attachments', () => { |
| 91 | + const json = { |
| 92 | + '@type': 'https://didcomm.org/out-of-band/1.1/invitation', |
| 93 | + '@id': '69212a3a-d068-4f9d-a2dd-4741bca89af3', |
| 94 | + label: 'Faber College', |
| 95 | + goal_code: 'issue-vc', |
| 96 | + goal: 'To issue a Faber College Graduate credential', |
| 97 | + handshake_protocols: ['https://didcomm.org/didexchange/1.0', 'https://didcomm.org/connections/1.0'], |
| 98 | + services: ['did:sov:LjgpST2rjsoxYegQDRm7EL'], |
| 99 | + '~attach': [ |
| 100 | + { |
| 101 | + '@id': 'view-1', |
| 102 | + 'mime-type': 'image/png', |
| 103 | + filename: 'IMG1092348.png', |
| 104 | + lastmod_time: '2018-12-24 18:24:07Z', |
| 105 | + description: 'view from doorway, facing east, with lights off', |
| 106 | + data: { |
| 107 | + base64: 'dmlldyBmcm9tIGRvb3J3YXksIGZhY2luZyBlYXN0LCB3aXRoIGxpZ2h0cyBvZmY=', |
| 108 | + }, |
| 109 | + }, |
| 110 | + { |
| 111 | + '@id': 'view-2', |
| 112 | + 'mime-type': 'image/png', |
| 113 | + filename: 'IMG1092349.png', |
| 114 | + lastmod_time: '2018-12-24 18:25:49Z', |
| 115 | + description: 'view with lamp in the background', |
| 116 | + data: { |
| 117 | + base64: 'dmlldyB3aXRoIGxhbXAgaW4gdGhlIGJhY2tncm91bmQ=', |
| 118 | + }, |
| 119 | + }, |
| 120 | + ], |
| 121 | + } |
| 122 | + |
| 123 | + const invitation = OutOfBandInvitation.fromJson(json) |
| 124 | + expect(invitation).toBeDefined() |
| 125 | + expect(invitation).toBeInstanceOf(OutOfBandInvitation) |
| 126 | + expect(invitation.appendedAttachments).toBeDefined() |
| 127 | + expect(invitation.appendedAttachments?.length).toEqual(2) |
| 128 | + expect(invitation.getAppendedAttachmentById('view-1')).toEqual( |
| 129 | + new Attachment({ |
| 130 | + id: 'view-1', |
| 131 | + mimeType: 'image/png', |
| 132 | + filename: 'IMG1092348.png', |
| 133 | + lastmodTime: new Date('2018-12-24 18:24:07Z'), |
| 134 | + description: 'view from doorway, facing east, with lights off', |
| 135 | + data: { |
| 136 | + base64: 'dmlldyBmcm9tIGRvb3J3YXksIGZhY2luZyBlYXN0LCB3aXRoIGxpZ2h0cyBvZmY=', |
| 137 | + }, |
| 138 | + }) |
| 139 | + ) |
| 140 | + expect(invitation.getAppendedAttachmentById('view-2')).toEqual( |
| 141 | + new Attachment({ |
| 142 | + id: 'view-2', |
| 143 | + mimeType: 'image/png', |
| 144 | + filename: 'IMG1092349.png', |
| 145 | + lastmodTime: new Date('2018-12-24 18:25:49Z'), |
| 146 | + description: 'view with lamp in the background', |
| 147 | + data: { |
| 148 | + base64: 'dmlldyB3aXRoIGxhbXAgaW4gdGhlIGJhY2tncm91bmQ=', |
| 149 | + }, |
| 150 | + }) |
| 151 | + ) |
| 152 | + }) |
| 153 | + |
89 | 154 | test('throw validation error when services attribute is empty', () => { |
90 | 155 | const json = { |
91 | 156 | '@type': 'https://didcomm.org/out-of-band/1.1/invitation', |
|
0 commit comments