forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudienceFeedbackService.test.js
45 lines (41 loc) · 1.86 KB
/
AudienceFeedbackService.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const assert = require('assert/strict');
const {AudienceFeedbackService} = require('../index');
describe('audienceFeedbackService', function () {
it('exported', function () {
assert.equal(require('../index').AudienceFeedbackService, AudienceFeedbackService);
});
const mockData = {
uuid: '7b11de3c-dff9-4563-82ae-a281122d201d',
postId: '634fc3901e0a291855d8b135',
postTitle: 'somepost',
score: 1
};
describe('build link', function () {
it('Can build link to post', async function () {
const instance = new AudienceFeedbackService({
urlService: {
getUrlByResourceId: () => `https://localhost:2368/${mockData.postTitle}/`
},
config: {
baseURL: new URL('https://localhost:2368')
}
});
const link = instance.buildLink(mockData.uuid, mockData.postId, mockData.score);
const expectedLink = `https://localhost:2368/${mockData.postTitle}/#/feedback/${mockData.postId}/${mockData.score}/?uuid=${mockData.uuid}`;
assert.equal(link.href, expectedLink);
});
it('Can build link to home page if post wasn\'t published', async function () {
const instance = new AudienceFeedbackService({
urlService: {
getUrlByResourceId: () => `https://localhost:2368/${mockData.postTitle}/404/`
},
config: {
baseURL: new URL('https://localhost:2368')
}
});
const link = instance.buildLink(mockData.uuid, mockData.postId, mockData.score);
const expectedLink = `https://localhost:2368/#/feedback/${mockData.postId}/${mockData.score}/?uuid=${mockData.uuid}`;
assert.equal(link.href, expectedLink);
});
});
});