This commit is contained in:
@@ -3,13 +3,25 @@ import {DocxService} from './docx.service';
|
||||
|
||||
describe('DocxService', () => {
|
||||
let service: DocxService;
|
||||
type PreparedData = {
|
||||
show: {
|
||||
showType: string;
|
||||
date: {toDate: () => Date};
|
||||
};
|
||||
songs: unknown[];
|
||||
user: {name: string};
|
||||
config: {ccliLicenseId: string};
|
||||
};
|
||||
type DocxModuleLike = {
|
||||
Packer: {toBlob: (document: unknown) => Promise<Blob>};
|
||||
};
|
||||
type DocxServiceInternals = DocxService & {
|
||||
prepareData: (showId: string) => Promise<unknown>;
|
||||
prepareData: (showId: string) => Promise<PreparedData | null>;
|
||||
renderTitle: (docx: unknown, title: string) => unknown[];
|
||||
renderSongs: (docx: unknown, songs: unknown[], options: unknown, config: unknown) => unknown[];
|
||||
prepareNewDocument: (docx: unknown, data: unknown, options?: unknown, sections?: unknown) => unknown;
|
||||
saveAs: (blob: Blob, name: string) => void;
|
||||
loadDocx: () => Promise<{Packer: {toBlob: (document: unknown) => Promise<Blob>}}>;
|
||||
loadDocx: () => Promise<DocxModuleLike>;
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -23,8 +35,8 @@ describe('DocxService', () => {
|
||||
|
||||
it('should not try to save a document when the required data cannot be prepared', async () => {
|
||||
const serviceInternals = service as DocxServiceInternals;
|
||||
const prepareDataSpy = spyOn<any>(serviceInternals, 'prepareData').and.resolveTo(null);
|
||||
const saveAsSpy = spyOn<any>(serviceInternals, 'saveAs');
|
||||
const prepareDataSpy = spyOn(serviceInternals, 'prepareData').and.resolveTo(null);
|
||||
const saveAsSpy = spyOn(serviceInternals, 'saveAs');
|
||||
|
||||
await service.create('show-1');
|
||||
|
||||
@@ -34,13 +46,13 @@ describe('DocxService', () => {
|
||||
|
||||
it('should build and save a docx file when all data is available', async () => {
|
||||
const blob = new Blob(['docx']);
|
||||
const docxModule = {
|
||||
const docxModule: DocxModuleLike = {
|
||||
Packer: {
|
||||
toBlob: jasmine.createSpy('toBlob').and.resolveTo(blob),
|
||||
},
|
||||
};
|
||||
const serviceInternals = service as DocxServiceInternals;
|
||||
const prepareDataSpy = spyOn<any>(serviceInternals, 'prepareData').and.resolveTo({
|
||||
const prepareDataSpy = spyOn(serviceInternals, 'prepareData').and.resolveTo({
|
||||
show: {
|
||||
showType: 'service-worship',
|
||||
date: {toDate: () => new Date('2026-03-10T00:00:00Z')},
|
||||
@@ -49,11 +61,11 @@ describe('DocxService', () => {
|
||||
user: {name: 'Benjamin'},
|
||||
config: {ccliLicenseId: '12345'},
|
||||
});
|
||||
spyOn<any>(serviceInternals, 'loadDocx').and.resolveTo(docxModule);
|
||||
spyOn<any>(serviceInternals, 'renderTitle').and.returnValue([]);
|
||||
spyOn<any>(serviceInternals, 'renderSongs').and.returnValue([]);
|
||||
const prepareNewDocumentSpy = spyOn<any>(serviceInternals, 'prepareNewDocument').and.returnValue({doc: true});
|
||||
const saveAsSpy = spyOn<any>(serviceInternals, 'saveAs');
|
||||
spyOn(serviceInternals, 'loadDocx').and.resolveTo(docxModule);
|
||||
spyOn(serviceInternals, 'renderTitle').and.returnValue([]);
|
||||
spyOn(serviceInternals, 'renderSongs').and.returnValue([]);
|
||||
const prepareNewDocumentSpy = spyOn(serviceInternals, 'prepareNewDocument').and.returnValue({doc: true});
|
||||
const saveAsSpy = spyOn(serviceInternals, 'saveAs');
|
||||
|
||||
await service.create('show-1', {copyright: true});
|
||||
|
||||
|
||||
@@ -56,10 +56,7 @@ describe('ShowService', () => {
|
||||
});
|
||||
|
||||
it('should not include archived shows from other users when requested', async () => {
|
||||
shows$.next([
|
||||
...(shows as unknown as unknown[]),
|
||||
{id: 'show-4', owner: 'other-user', published: true, archived: true},
|
||||
]);
|
||||
shows$.next([...(shows as unknown as unknown[]), {id: 'show-4', owner: 'other-user', published: true, archived: true}]);
|
||||
|
||||
const result = await firstValueFrom(service.list$(false, true));
|
||||
expect(result.map(show => show.id)).toEqual(['show-1', 'show-2', 'show-3']);
|
||||
|
||||
@@ -27,9 +27,7 @@ export class ShowService {
|
||||
(user: User | null, shows: Show[]) => ({user, shows})
|
||||
),
|
||||
map(s =>
|
||||
s.shows
|
||||
.filter(show => !show.archived || (includeOwnArchived && show.owner === s.user?.id))
|
||||
.filter(show => show.published || (show.owner === s.user?.id && !publishedOnly))
|
||||
s.shows.filter(show => !show.archived || (includeOwnArchived && show.owner === s.user?.id)).filter(show => show.published || (show.owner === s.user?.id && !publishedOnly))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user