Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/renderer/src/burrito/useBurritoAudio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/src/burrito/useBurritoAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/burrito/useBurritoNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down
67 changes: 66 additions & 1 deletion src/renderer/src/burrito/useCreateBurrito.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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() {
Expand Down Expand Up @@ -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');
});
});

37 changes: 22 additions & 15 deletions src/renderer/src/burrito/useCreateBurrito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -146,54 +148,59 @@ 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<string, { revision: string; timestamp: string }>,
},
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')
.withLocalizedNames(localizedNames)
.withCopyright({
shortStatements: [
{
statement: `<p>${copyright}</p>`,
statement: `<p>${(copyright || '').trim()}</p>`,
mimetype: 'text/html',
lang: 'en',
},
Expand All @@ -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;
};
Expand Down
Loading