Commits
Gantner, Florian Klaus authored and github-actions[bot] committed 202c84c4840
1 1 | import { ListableObject } from '../../shared/object-collection/shared/listable-object.model'; |
2 2 | import { DSpaceObject } from '../shared/dspace-object.model'; |
3 3 | import { GenericConstructor } from '../shared/generic-constructor'; |
4 4 | import { Item } from '../shared/item.model'; |
5 5 | import { MetadataValueFilter } from '../shared/metadata.models'; |
6 6 | import { DSONameService } from './dso-name.service'; |
7 7 | |
8 8 | describe(`DSONameService`, () => { |
9 9 | let service: DSONameService; |
10 10 | let mockPersonName: string; |
11 11 | let mockPerson: DSpaceObject; |
12 + | let mockEPersonNameFirst: string; |
13 + | let mockEPersonFirst: DSpaceObject; |
14 + | let mockEPersonName: string; |
15 + | let mockEPerson: DSpaceObject; |
12 16 | let mockOrgUnitName: string; |
13 17 | let mockOrgUnit: DSpaceObject; |
14 18 | let mockDSOName: string; |
15 19 | let mockDSO: DSpaceObject; |
16 20 | |
17 21 | beforeEach(() => { |
18 22 | mockPersonName = 'Doe, John'; |
19 23 | mockPerson = Object.assign(new DSpaceObject(), { |
20 24 | firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string { |
21 25 | return mockPersonName; |
22 26 | }, |
23 27 | getRenderTypes(): (string | GenericConstructor<ListableObject>)[] { |
24 28 | return ['Person', Item, DSpaceObject]; |
25 29 | } |
26 30 | }); |
27 31 | |
32 + | mockEPersonName = 'John Doe'; |
33 + | mockEPerson = Object.assign(new DSpaceObject(), { |
34 + | firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string { |
35 + | return mockEPersonName; |
36 + | }, |
37 + | getRenderTypes(): (string | GenericConstructor<ListableObject>)[] { |
38 + | return ['EPerson', Item, DSpaceObject]; |
39 + | }, |
40 + | }); |
41 + | |
42 + | mockEPersonNameFirst = 'John'; |
43 + | mockEPersonFirst = Object.assign(new DSpaceObject(), { |
44 + | firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string { |
45 + | return mockEPersonNameFirst; |
46 + | }, |
47 + | getRenderTypes(): (string | GenericConstructor<ListableObject>)[] { |
48 + | return ['EPerson', Item, DSpaceObject]; |
49 + | }, |
50 + | }); |
51 + | |
28 52 | mockOrgUnitName = 'Molecular Spectroscopy'; |
29 53 | mockOrgUnit = Object.assign(new DSpaceObject(), { |
30 54 | firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string { |
31 55 | return mockOrgUnitName; |
32 56 | }, |
33 57 | getRenderTypes(): (string | GenericConstructor<ListableObject>)[] { |
34 58 | return ['OrgUnit', Item, DSpaceObject]; |
35 59 | } |
36 60 | }); |
37 61 | |
60 84 | |
61 85 | it(`should use the OrgUnit factory for OrgUnit entities`, () => { |
62 86 | spyOn((service as any).factories, 'OrgUnit').and.returnValue('Bingo!'); |
63 87 | |
64 88 | const result = service.getName(mockOrgUnit); |
65 89 | |
66 90 | expect((service as any).factories.OrgUnit).toHaveBeenCalledWith(mockOrgUnit); |
67 91 | expect(result).toBe('Bingo!'); |
68 92 | }); |
69 93 | |
94 + | it(`should use the EPerson factory for EPerson objects`, () => { |
95 + | spyOn((service as any).factories, 'EPerson').and.returnValue('Bingo!'); |
96 + | |
97 + | const result = service.getName(mockEPerson); |
98 + | |
99 + | expect((service as any).factories.EPerson).toHaveBeenCalledWith(mockEPerson); |
100 + | expect(result).toBe('Bingo!'); |
101 + | }); |
102 + | |
70 103 | it(`should use the Default factory for regular DSpaceObjects`, () => { |
71 104 | spyOn((service as any).factories, 'Default').and.returnValue('Bingo!'); |
72 105 | |
73 106 | const result = service.getName(mockDSO); |
74 107 | |
75 108 | expect((service as any).factories.Default).toHaveBeenCalledWith(mockDSO); |
76 109 | expect(result).toBe('Bingo!'); |
77 110 | }); |
78 111 | }); |
79 112 | |
100 133 | it(`should return dc.title`, () => { |
101 134 | const result = (service as any).factories.Person(mockPerson); |
102 135 | expect(result).toBe(mockPersonName); |
103 136 | expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('person.familyName'); |
104 137 | expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('person.givenName'); |
105 138 | expect(mockPerson.firstMetadataValue).toHaveBeenCalledWith('dc.title'); |
106 139 | }); |
107 140 | }); |
108 141 | }); |
109 142 | |
143 + | describe(`factories.EPerson`, () => { |
144 + | describe(`with eperson.firstname and without eperson.lastname`, () => { |
145 + | beforeEach(() => { |
146 + | spyOn(mockEPerson, 'firstMetadataValue').and.returnValues(mockEPersonName.split(' ')); |
147 + | }); |
148 + | |
149 + | it(`should return 'eperson.firstname' and 'eperson.lastname'`, () => { |
150 + | const result = (service as any).factories.EPerson(mockEPerson); |
151 + | expect(result).toBe(mockEPersonName); |
152 + | expect(mockEPerson.firstMetadataValue).toHaveBeenCalledWith('eperson.firstname'); |
153 + | expect(mockEPerson.firstMetadataValue).toHaveBeenCalledWith('eperson.lastname'); |
154 + | }); |
155 + | }); |
156 + | |
157 + | describe(` with eperson.firstname and without eperson.lastname`, () => { |
158 + | beforeEach(() => { |
159 + | spyOn(mockEPersonFirst, 'firstMetadataValue').and.returnValues(mockEPersonNameFirst, undefined); |
160 + | }); |
161 + | |
162 + | it(`should return 'eperson.firstname'`, () => { |
163 + | const result = (service as any).factories.EPerson(mockEPersonFirst); |
164 + | expect(result).toBe(mockEPersonNameFirst); |
165 + | expect(mockEPersonFirst.firstMetadataValue).toHaveBeenCalledWith('eperson.firstname'); |
166 + | expect(mockEPersonFirst.firstMetadataValue).toHaveBeenCalledWith('eperson.lastname'); |
167 + | }); |
168 + | }); |
169 + | }); |
170 + | |
171 + | |
110 172 | describe(`factories.OrgUnit`, () => { |
111 173 | beforeEach(() => { |
112 174 | spyOn(mockOrgUnit, 'firstMetadataValue').and.callThrough(); |
113 175 | }); |
114 176 | |
115 177 | it(`should return 'organization.legalName'`, () => { |
116 178 | const result = (service as any).factories.OrgUnit(mockOrgUnit); |
117 179 | expect(result).toBe(mockOrgUnitName); |
118 180 | expect(mockOrgUnit.firstMetadataValue).toHaveBeenCalledWith('organization.legalName'); |
119 181 | }); |