Skip to content

Commit

Permalink
fix: missing type in serialization of shared items
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
  • Loading branch information
genaris committed Jan 27, 2023
1 parent 7ecade6 commit 0cdd143
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/repository/MediaSharingRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { v4 as uuid } from 'uuid'
import { AriesFrameworkError, Attachment, AttachmentData, BaseRecord } from '@aries-framework/core'
import { MediaSharingRole, MediaSharingState } from '../model'
import { AttachmentOptions } from '@aries-framework/core/build/decorators/attachment/Attachment'
import { Exclude } from 'class-transformer'
import { Exclude, Type } from 'class-transformer'

export interface CipheringInfo {
algorithm: string
Expand Down Expand Up @@ -53,6 +53,8 @@ export class MediaSharingRecord extends BaseRecord {
public role!: MediaSharingRole
public state!: MediaSharingState
public description?: string

@Type(() => SharedMediaItem)
public items?: SharedMediaItem[]

public static readonly type = 'MediaSharingRecord'
Expand Down
18 changes: 15 additions & 3 deletions test/mediasharing.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { agentDependencies } from '@aries-framework/node'
import { Agent, ConnectionRecord, ConsoleLogger, EncryptedMessage, LogLevel } from '@aries-framework/core'
import { Agent, ConnectionRecord, ConsoleLogger, EncryptedMessage, JsonTransformer, LogLevel } from '@aries-framework/core'
import { v4 as uuid } from 'uuid'
import { firstValueFrom, ReplaySubject, Subject } from 'rxjs'
import { MediaSharingModule } from '../src/MediaSharingModule'
import { MediaSharingRecord } from '../src/repository'
import { MediaSharingRecord, SharedMediaItem } from '../src/repository'
import { SubjectOutboundTransport } from './transport/SubjectOutboundTransport'
import { SubjectInboundTransport } from './transport/SubjectInboundTransport'
import { recordsAddedByType } from './recordUtils'
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('media test', () => {

await aliceAgent.modules.media.share({
recordId: aliceRecord.id,
items: [{ mimeType: 'image/png', uri: 'http://blabla' }],
items: [{ mimeType: 'image/png', uri: 'http://blabla', metadata: { duration: 14 } }],
})

recordsAddedByType(bobAgent, MediaSharingRecord)
Expand All @@ -139,8 +139,20 @@ describe('media test', () => {
const bobRecord = await firstValueFrom(subjectBob)
await firstValueFrom(subjectAlice)

console.log(bobRecord.items![0])
expect(bobRecord.items?.length).toBe(1)
expect(bobRecord.items![0].mimeType).toBe('image/png')
expect(bobRecord.items![0].uri).toBe('http://blabla')
expect(bobRecord.items![0].metadata!.duration).toBe(14)

// Now retrieve from repository
const recordFromRepo = await bobAgent.modules.media.findById(bobRecord.id)
expect(recordFromRepo).toBeDefined()
expect(recordFromRepo!.items?.length).toBe(1)

const item = recordFromRepo!.items![0]
expect(item.mimeType).toBe('image/png')
expect(item.uri).toBe('http://blabla')
expect(item.metadata!.duration).toBe(14)
})
})

0 comments on commit 0cdd143

Please sign in to comment.