Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated feedback buttons url #15655

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
11 changes: 10 additions & 1 deletion ghost/audience-feedback/lib/AudienceFeedbackService.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
class AudienceFeedbackService {
/** @type URL */
#baseURL;
/** @type {Object} */
#urlService;
/**
* @param {object} deps
* @param {object} deps.config
* @param {URL} deps.config.baseURL
* @param {object} deps.urlService
*/
constructor(deps) {
this.#baseURL = deps.config.baseURL;
this.#urlService = deps.urlService;
}
/**
* @param {string} uuid
* @param {string} postId
* @param {0 | 1} score
*/
buildLink(uuid, postId, score) {
const url = new URL(this.#baseURL);
let postUrl = this.#urlService.getUrlByResourceId(postId, {absolute: true});

if (postUrl.match(/\/404\//)) {
postUrl = this.#baseURL;
}
const url = new URL(postUrl);
url.searchParams.set('action', 'feedback');
url.searchParams.set('post', postId);
url.searchParams.set('uuid', uuid);
Expand Down
45 changes: 45 additions & 0 deletions ghost/audience-feedback/test/AudienceFeedbackService.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const assert = require('assert');
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}/?action=feedback&post=${mockData.postId}&uuid=${mockData.uuid}&score=${mockData.score}`;
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/?action=feedback&post=${mockData.postId}&uuid=${mockData.uuid}&score=${mockData.score}`;
assert.equal(link.href, expectedLink);
});
});
});
10 changes: 0 additions & 10 deletions ghost/audience-feedback/test/hello.test.js

This file was deleted.

2 changes: 2 additions & 0 deletions ghost/core/core/server/services/audience-feedback/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const urlUtils = require('../../../shared/url-utils');
const urlService = require('../../services/url');
const FeedbackRepository = require('./FeedbackRepository');

class AudienceFeedbackServiceWrapper {
Expand All @@ -22,6 +23,7 @@ class AudienceFeedbackServiceWrapper {

// Expose the service
this.service = new AudienceFeedbackService({
urlService,
config: {
baseURL: new URL(urlUtils.urlFor('home', true))
}
Expand Down