diff --git a/src/renderer/src/burrito/useBurritoAudio.test.ts b/src/renderer/src/burrito/useBurritoAudio.test.ts index 8995ab10..c488d930 100644 --- a/src/renderer/src/burrito/useBurritoAudio.test.ts +++ b/src/renderer/src/burrito/useBurritoAudio.test.ts @@ -366,6 +366,8 @@ describe('useBurritoAudio', () => { expect(ipIngredient).toBeDefined(); expect(ipIngredient![0]).toContain('rights-statement'); expect(ipIngredient![1].mimeType).toBe('audio/mpeg'); + expect(ipIngredient![1].scope).toEqual({ GEN: [] }); + expect(ipIngredient![1].scope?.GEN).not.toContain(''); useArtifactType.mockImplementation(() => ({ slugFromId: jest.fn(() => 'vernacular'), diff --git a/src/renderer/src/burrito/useBurritoAudio.ts b/src/renderer/src/burrito/useBurritoAudio.ts index bb494180..ac36d21f 100644 --- a/src/renderer/src/burrito/useBurritoAudio.ts +++ b/src/renderer/src/burrito/useBurritoAudio.ts @@ -240,7 +240,7 @@ export const useBurritoAudio = (teamId: string) => { ? 'audio/mpeg' : inferAudioContentType(finalPath, attr.contentType), size, - scope: { [book]: [scopeRef] }, + scope: { [book]: scopeRef ? [scopeRef] : [] }, properties: { apmId: m.keys?.remoteId || m.id, }, @@ -263,7 +263,7 @@ export const useBurritoAudio = (teamId: string) => { checksum: { md5: await ipc?.md5File(finalPath) }, mimeType: attr.contentType, size: attr.originalFile.length, - scope: { [book]: [scopeRef] }, + scope: { [book]: scopeRef ? [scopeRef] : [] }, properties: { apmId: m.keys?.remoteId || m.id, }, @@ -287,7 +287,7 @@ export const useBurritoAudio = (teamId: string) => { checksum: { md5: await ipc?.md5File(finalPath) }, mimeType: attr.contentType || 'text/plain', size: attr.originalFile.length, - scope: { [book]: [scopeRef] }, + scope: { [book]: scopeRef ? [scopeRef] : [] }, properties: { apmId: m.keys?.remoteId || m.id, }, @@ -309,7 +309,7 @@ export const useBurritoAudio = (teamId: string) => { checksum: { md5: await ipc?.md5File(finalPath) }, mimeType: 'text/plain', size: url.length + 1, - scope: { [book]: [scopeRef] }, + scope: { [book]: scopeRef ? [scopeRef] : [] }, properties: { apmId: m.keys?.remoteId || m.id, }, diff --git a/src/renderer/src/burrito/useBurritoNavigation.ts b/src/renderer/src/burrito/useBurritoNavigation.ts index 76f34d10..49271a73 100644 --- a/src/renderer/src/burrito/useBurritoNavigation.ts +++ b/src/renderer/src/burrito/useBurritoNavigation.ts @@ -277,7 +277,7 @@ export const useBurritoNavigation = (teamId: string) => { checksum: { md5: await ipc?.md5File(destPath) }, mimeType: attr.contentType || 'image/png', size, - scope: { [book]: [scopeRef] }, + scope: { [book]: scopeRef ? [scopeRef] : [] }, properties: { apmId: m.keys?.remoteId || m.id, }, @@ -370,7 +370,7 @@ export const useBurritoNavigation = (teamId: string) => { checksum: { md5: await ipc?.md5File(destPath) }, mimeType: imgInfo.type || 'image/png', size: stat?.size ?? 0, - scope: { [book]: [scopeRef] }, + scope: { [book]: scopeRef ? [scopeRef] : [] }, properties: { apmId: g.keys?.remoteId || g.id, }, diff --git a/src/renderer/src/burrito/useCreateBurrito.test.ts b/src/renderer/src/burrito/useCreateBurrito.test.ts index 9d7fc165..121ee6d9 100644 --- a/src/renderer/src/burrito/useCreateBurrito.test.ts +++ b/src/renderer/src/burrito/useCreateBurrito.test.ts @@ -42,6 +42,7 @@ jest.mock('./data/burritoBuilder', () => ({ meta: { version: '0.1', category: 'scripture' }, ingredients: {}, type: { flavorType: { name: 'scripture', flavor: { name: 'base' }, currentScope: {} } }, + identification: {}, }; withMeta(meta: any) { this.obj.meta = { ...this.obj.meta, ...meta }; @@ -50,7 +51,11 @@ jest.mock('./data/burritoBuilder', () => ({ withIdAuthority() { return this; } - withIdentification() { + withIdentification(identification: any) { + this.obj.identification = { + ...this.obj.identification, + ...identification, + }; return this; } withAgency() { @@ -323,5 +328,65 @@ describe('useCreateBurrito', () => { await act(async () => Promise.resolve()); expect(dispatch).toHaveBeenCalled(); }); + + it('trims identification.name.en and language display names in metadata', async () => { + const ipc = makeIpc(); + const { user, team, bible, teamBible } = fixtures(teamId); + bible.attributes.bibleName = ' Trimmed Bible '; + const project = { + id: 'proj-1', + type: 'project', + attributes: { + name: 'Proj', + language: 'eng', + languageName: ' English ', + }, + relationships: {}, + } as any; + const plan = { + id: 'plan-1', + type: 'plan', + relationships: { project: { data: { id: 'proj-1' } } }, + } as any; + + const { renderHook, act, useCreateBurrito } = loadCreateBurrito(ipc as never, { + orgDefaults: { + burritoBooks: ['GEN'], + burritoContents: [BurritoType.Text], + burritoWrapper: { wrapper: true }, + burritoProjects: ['proj-1'], + burritoFormat: { convertToMp3: false }, + burritoRevision: ' 2 ', + }, + orbit: { + user: [user], + organization: [team], + organizationbible: [teamBible], + bible: [bible], + project: [project], + plan: [plan], + section: [], + passage: [], + }, + }); + + const { result } = renderHook(() => useCreateBurrito(teamId)); + + await act(async () => { + await result.current.createBurrito(); + }); + + const metaWrites = ipc.write.mock.calls.filter((c) => + String(c[0]).includes('metadata.json') + ); + expect(metaWrites.length).toBeGreaterThan(0); + const metadata = JSON.parse(metaWrites[metaWrites.length - 1][1] as string); + expect(metadata.identification?.name?.en).toBe('Trimmed Bible'); + expect(metadata.identification?.abbreviation?.en).toBe('TST'); + expect(metadata.languages).toEqual([ + { tag: 'eng', name: { en: 'English' } }, + ]); + expect(metadata.identification?.primary?.apm?.['rem-1']?.revision).toBe('2'); + }); }); diff --git a/src/renderer/src/burrito/useCreateBurrito.ts b/src/renderer/src/burrito/useCreateBurrito.ts index 9582427c..90d69918 100644 --- a/src/renderer/src/burrito/useCreateBurrito.ts +++ b/src/renderer/src/burrito/useCreateBurrito.ts @@ -132,7 +132,9 @@ export const useCreateBurrito = (teamId: string) => { const teamRec = teams.find((team) => team.id === teamId); const teamRemId = remoteId('organization', teamId, memory.keyMap as RecordKeyMap) || teamId; - const revision = getOrgDefault('burritoRevision', teamId) || '1'; + const revision = ( + (getOrgDefault('burritoRevision', teamId) as string) || '1' + ).trim(); const localizedNames = {} as BurritoLocalizedNames; books.forEach((book) => { const bookInfo = bookData(book); @@ -146,46 +148,51 @@ export const useCreateBurrito = (teamId: string) => { const metaData = new BurritoBuilder() .withMeta({ generator: { - softwareName: productName, - softwareVersion: version, - userName: userRec?.attributes.name || 'Unknown User', + softwareName: productName.trim(), + softwareVersion: version.trim(), + userName: (userRec?.attributes.name || 'Unknown User').trim(), }, comments: [ - `Generated by Audio Project Manager from ${ + `Generated by Audio Project Manager from ${( teamRec?.attributes.name || 'Unknown Team' - }`, + ).trim()}`, ], }) .withIdAuthority( 'apm', 'https://www.audioprojectmanager.org', - productName + productName.trim() ) .withIdentification({ primary: { apm: { [teamRemId]: { - revision, + revision: revision, timestamp: new Date().toISOString(), }, } as Record, }, name: { - en: + en: ( cleanName(bible?.attributes.bibleName || '') || cleanName(teamRec?.attributes.name || '') || - 'Unknown Bible', + 'Unknown Bible' + ).trim(), }, - description: { en: bible?.attributes.description || '' }, + description: { en: (bible?.attributes.description || '').trim() }, abbreviation: { - en: bible?.attributes.bibleId || `${bible?.attributes.iso}New`, + en: ( + bible?.attributes.bibleId || `${bible?.attributes.iso}New` + ).trim(), }, }) .withAgency({ id: `apm::${teamRemId}`, roles: ['rightsHolder'], name: { - en: cleanName(teamRec?.attributes.name || '') || 'Unknown Team', + en: ( + cleanName(teamRec?.attributes.name || '') || 'Unknown Team' + ).trim(), }, }) .withTargetArea('US', 'United States') @@ -193,7 +200,7 @@ export const useCreateBurrito = (teamId: string) => { .withCopyright({ shortStatements: [ { - statement: `

${copyright}

`, + statement: `

${(copyright || '').trim()}

`, mimetype: 'text/html', lang: 'en', }, @@ -202,7 +209,7 @@ export const useCreateBurrito = (teamId: string) => { .build(); metaData.languages = languages.map((l) => { const [lang, name] = l.split('|'); - return { tag: lang, name: { en: name } }; + return { tag: lang, name: { en: name.trim() } }; }); return metaData; };