|
|
|
@ -23,11 +23,12 @@ describe('ContentDto', () => { |
|
|
|
const creator = 'not-me'; |
|
|
|
const modified = DateTime.now(); |
|
|
|
const modifier = 'me'; |
|
|
|
const dueTime = DateTime.now().addDays(1); |
|
|
|
const version = new Version('1'); |
|
|
|
const newVersion = new Version('2'); |
|
|
|
|
|
|
|
it('should update data property and user info when updating', () => { |
|
|
|
const content_1 = new ContentDto('1', 'Published', creator, creator, creation, creation, { data: 1 }, version); |
|
|
|
const content_1 = new ContentDto('1', 'Published', creator, creator, creation, creation, null, null, null, { data: 1 }, version); |
|
|
|
const content_2 = content_1.update({ data: 2 }, modifier, newVersion, modified); |
|
|
|
|
|
|
|
expect(content_2.data).toEqual({ data: 2 }); |
|
|
|
@ -36,9 +37,9 @@ describe('ContentDto', () => { |
|
|
|
expect(content_2.version).toEqual(newVersion); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should update status property and user info when publishing', () => { |
|
|
|
const content_1 = new ContentDto('1', 'Draft', creator, creator, creation, creation, { data: 1 }, version); |
|
|
|
const content_2 = content_1.publish(modifier, newVersion, modified); |
|
|
|
it('should update status property and user info when changing status', () => { |
|
|
|
const content_1 = new ContentDto('1', 'Draft', creator, creator, creation, creation, null, null, null, { data: 1 }, version); |
|
|
|
const content_2 = content_1.changeStatus('Published', modifier, newVersion, modified); |
|
|
|
|
|
|
|
expect(content_2.status).toEqual('Published'); |
|
|
|
expect(content_2.lastModified).toEqual(modified); |
|
|
|
@ -46,40 +47,23 @@ describe('ContentDto', () => { |
|
|
|
expect(content_2.version).toEqual(newVersion); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should update status property and user info when unpublishing', () => { |
|
|
|
const content_1 = new ContentDto('1', 'Published', creator, creator, creation, creation, { data: 1 }, version); |
|
|
|
const content_2 = content_1.unpublish(modifier, newVersion, modified); |
|
|
|
|
|
|
|
expect(content_2.status).toEqual('Draft'); |
|
|
|
expect(content_2.lastModified).toEqual(modified); |
|
|
|
expect(content_2.lastModifiedBy).toEqual(modifier); |
|
|
|
expect(content_2.version).toEqual(newVersion); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should update status property and user info when archiving', () => { |
|
|
|
const content_1 = new ContentDto('1', 'Draft', creator, creator, creation, creation, { data: 1 }, version); |
|
|
|
const content_2 = content_1.archive(modifier, newVersion, modified); |
|
|
|
|
|
|
|
expect(content_2.status).toEqual('Archived'); |
|
|
|
expect(content_2.lastModified).toEqual(modified); |
|
|
|
expect(content_2.lastModifiedBy).toEqual(modifier); |
|
|
|
expect(content_2.version).toEqual(newVersion); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should update status property and user info when restoring', () => { |
|
|
|
const content_1 = new ContentDto('1', 'Archived', creator, creator, creation, creation, { data: 1 }, version); |
|
|
|
const content_2 = content_1.restore(modifier, newVersion, modified); |
|
|
|
it('should update schedules property and user info when changing status with due time', () => { |
|
|
|
const content_1 = new ContentDto('1', 'Draft', creator, creator, creation, creation, null, null, null, { data: 1 }, version); |
|
|
|
const content_2 = content_1.changeStatus('Published', modifier, newVersion, modified, dueTime); |
|
|
|
|
|
|
|
expect(content_2.status).toEqual('Draft'); |
|
|
|
expect(content_2.lastModified).toEqual(modified); |
|
|
|
expect(content_2.lastModifiedBy).toEqual(modifier); |
|
|
|
expect(content_2.scheduledAt).toEqual(dueTime); |
|
|
|
expect(content_2.scheduledBy).toEqual(modifier); |
|
|
|
expect(content_2.scheduledTo).toEqual('Published'); |
|
|
|
expect(content_2.version).toEqual(newVersion); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should update data property when setting data', () => { |
|
|
|
const newData = {}; |
|
|
|
|
|
|
|
const content_1 = new ContentDto('1', 'Published', creator, creator, creation, creation, { data: 1 }, version); |
|
|
|
const content_1 = new ContentDto('1', 'Published', creator, creator, creation, creation, null, null, null, { data: 1 }, version); |
|
|
|
const content_2 = content_1.setData(newData); |
|
|
|
|
|
|
|
expect(content_2.data).toBe(newData); |
|
|
|
@ -130,6 +114,9 @@ describe('ContentsService', () => { |
|
|
|
createdBy: 'Created1', |
|
|
|
lastModified: '2017-12-12T10:10', |
|
|
|
lastModifiedBy: 'LastModifiedBy1', |
|
|
|
scheduledTo: 'Draft', |
|
|
|
scheduledBy: 'Scheduler1', |
|
|
|
scheduledAt: '2018-12-12T10:10', |
|
|
|
version: 11, |
|
|
|
data: {} |
|
|
|
}, |
|
|
|
@ -151,11 +138,17 @@ describe('ContentsService', () => { |
|
|
|
new ContentDto('id1', 'Published', 'Created1', 'LastModifiedBy1', |
|
|
|
DateTime.parseISO_UTC('2016-12-12T10:10'), |
|
|
|
DateTime.parseISO_UTC('2017-12-12T10:10'), |
|
|
|
'Draft', |
|
|
|
'Scheduler1', |
|
|
|
DateTime.parseISO_UTC('2018-12-12T10:10'), |
|
|
|
{}, |
|
|
|
new Version('11')), |
|
|
|
new ContentDto('id2', 'Published', 'Created2', 'LastModifiedBy2', |
|
|
|
DateTime.parseISO_UTC('2016-10-12T10:10'), |
|
|
|
DateTime.parseISO_UTC('2017-10-12T10:10'), |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
{}, |
|
|
|
new Version('22')) |
|
|
|
])); |
|
|
|
@ -221,6 +214,9 @@ describe('ContentsService', () => { |
|
|
|
createdBy: 'Created1', |
|
|
|
lastModified: '2017-12-12T10:10', |
|
|
|
lastModifiedBy: 'LastModifiedBy1', |
|
|
|
scheduledTo: 'Draft', |
|
|
|
scheduledBy: 'Scheduler1', |
|
|
|
scheduledAt: '2018-12-12T10:10', |
|
|
|
data: {} |
|
|
|
}, { |
|
|
|
headers: { |
|
|
|
@ -232,6 +228,9 @@ describe('ContentsService', () => { |
|
|
|
new ContentDto('id1', 'Published', 'Created1', 'LastModifiedBy1', |
|
|
|
DateTime.parseISO_UTC('2016-12-12T10:10'), |
|
|
|
DateTime.parseISO_UTC('2017-12-12T10:10'), |
|
|
|
'Draft', |
|
|
|
'Scheduler1', |
|
|
|
DateTime.parseISO_UTC('2018-12-12T10:10'), |
|
|
|
{}, |
|
|
|
new Version('2'))); |
|
|
|
})); |
|
|
|
@ -270,6 +269,9 @@ describe('ContentsService', () => { |
|
|
|
new ContentDto('id1', 'Published', 'Created1', 'LastModifiedBy1', |
|
|
|
DateTime.parseISO_UTC('2016-12-12T10:10'), |
|
|
|
DateTime.parseISO_UTC('2017-12-12T10:10'), |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
{}, |
|
|
|
new Version('2'))); |
|
|
|
})); |
|
|
|
@ -310,10 +312,10 @@ describe('ContentsService', () => { |
|
|
|
req.flush({}); |
|
|
|
})); |
|
|
|
|
|
|
|
it('should make put request to publish content', |
|
|
|
it('should make put request to change content status', |
|
|
|
inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
contentsService.publishContent('my-app', 'my-schema', 'content1', version).subscribe(); |
|
|
|
contentsService.changeContentStatus('my-app', 'my-schema', 'content1', 'publish', version).subscribe(); |
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema/content1/publish'); |
|
|
|
|
|
|
|
@ -323,38 +325,14 @@ describe('ContentsService', () => { |
|
|
|
req.flush({}); |
|
|
|
})); |
|
|
|
|
|
|
|
it('should make put request to unpublish content', |
|
|
|
inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
contentsService.unpublishContent('my-app', 'my-schema', 'content1', version).subscribe(); |
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema/content1/unpublish'); |
|
|
|
|
|
|
|
expect(req.request.method).toEqual('PUT'); |
|
|
|
expect(req.request.headers.get('If-Match')).toEqual(version.value); |
|
|
|
|
|
|
|
req.flush({}); |
|
|
|
})); |
|
|
|
|
|
|
|
it('should make put request to archive content', |
|
|
|
it('should make put request with due time when status change is scheduled', |
|
|
|
inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
contentsService.archiveContent('my-app', 'my-schema', 'content1', version).subscribe(); |
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema/content1/archive'); |
|
|
|
|
|
|
|
expect(req.request.method).toEqual('PUT'); |
|
|
|
expect(req.request.headers.get('If-Match')).toEqual(version.value); |
|
|
|
|
|
|
|
req.flush({}); |
|
|
|
})); |
|
|
|
|
|
|
|
it('should make put request to restore content', |
|
|
|
inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => { |
|
|
|
const dueTime = DateTime.parseISO_UTC('2016-12-12T10:10'); |
|
|
|
|
|
|
|
contentsService.restoreContent('my-app', 'my-schema', 'content1', version).subscribe(); |
|
|
|
contentsService.changeContentStatus('my-app', 'my-schema', 'content1', 'publish', version, dueTime).subscribe(); |
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema/content1/restore'); |
|
|
|
const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema/content1/publish?dueTime=2016-12-12T10:10:00.000Z'); |
|
|
|
|
|
|
|
expect(req.request.method).toEqual('PUT'); |
|
|
|
expect(req.request.headers.get('If-Match')).toEqual(version.value); |
|
|
|
|