Skip to content

Commit

Permalink
Updated feedback buttons url
Browse files Browse the repository at this point in the history
closes TryGhost/Team#2080
- If the post was published and emailed the link leads the user to the post.
- If the post was just emailed the link leads the user to the home page.
  • Loading branch information
lenabaidakova committed Oct 19, 2022
1 parent 4f54cbc commit 8de9997
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
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

0 comments on commit 8de9997

Please sign in to comment.