2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Updated counts api url (#12)

closes TryGhost/Team#2094
- Counts request was changed from `post` to `get` for enable request caching.
This commit is contained in:
Elena Baidakova 2022-11-02 10:02:26 +04:00 committed by GitHub
parent 883a9728ca
commit 290e3d5713
4 changed files with 65 additions and 18 deletions

View file

@ -4,18 +4,20 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Basic Setup
This section is mostly relevant for core team only for active Comments development.
- Run `yarn start:dev` to start Comments in development mode
- Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
- To use the local Comments script in a local Ghost site
- Update `config.local.json` in Ghost repo to add "comments" config pointing to local dev server url as instructed on terminal.
- By default, this uses port `5368` for loading local Comments script on Ghost site. It's also possible to specify a custom port when running the script using - `--port=xxxx`.
## Available Scripts
In the project directory, you can run:
### `yarn start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
The page will reload when you make changes.\
You may also see any lint errors in the console.
### `yarn test`
Launches the test runner in the interactive watch mode.\
@ -74,4 +76,4 @@ This section has moved here: [https://facebook.github.io/create-react-app/docs/t
# Copyright & License
Copyright (c) 2013-2022 Ghost Foundation - Released under the [MIT license](LICENSE).
Copyright (c) 2013-2022 Ghost Foundation - Released under the [MIT license](LICENSE).

View file

@ -15,8 +15,8 @@ Cypress.Commands.add('login', (memberData) => {
Cypress.Commands.add('mockAddComments', () => {
cy.intercept(
{
method: 'POST',
url: '/members/api/comments/'
method: 'GET',
url: '/members/api/comments/counts/'
},
[] // and force the response to be: []
).as('getCounts'); // and assign an alias
@ -47,7 +47,7 @@ Cypress.Commands.add('mockComments', (count, override = {}) => {
cy.intercept(
{
method: 'POST',
method: 'GET',
url: '/members/api/comments/counts/'
},
[]

View file

@ -101,17 +101,15 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) {
api.comments = {
async count({postId}) {
const url = endpointFor({type: 'members', resource: 'comments/counts'});
const params = postId ? `?ids=${postId}` : '';
const url = endpointFor({type: 'members', resource: `comments/counts`, params});
const response = await makeRequest({
url,
method: 'POST',
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
credentials: 'same-origin',
body: JSON.stringify({
ids: [postId]
})
credentials: 'same-origin'
});
const json = await response.json();

View file

@ -0,0 +1,47 @@
import setupGhostApi from './api';
test('should call counts endpoint', () => {
jest.spyOn(window, 'fetch');
window.fetch.mockResolvedValueOnce({
ok: true,
json: async () => ({success: true})
});
const api = setupGhostApi({});
api.comments.count({postId: null});
expect(window.fetch).toHaveBeenCalledTimes(1);
expect(window.fetch).toHaveBeenCalledWith(
'http://localhost/members/api/comments/counts/',
expect.objectContaining({
method: 'GET',
headers: {'Content-Type': 'application/json'},
credentials: 'same-origin',
body: undefined
}),
);
});
test('should call counts endpoint with postId query param', () => {
jest.spyOn(window, 'fetch');
window.fetch.mockResolvedValueOnce({
ok: true,
json: async () => ({success: true})
});
const api = setupGhostApi({});
api.comments.count({postId: '123'});
expect(window.fetch).toHaveBeenCalledTimes(1);
expect(window.fetch).toHaveBeenCalledWith(
'http://localhost/members/api/comments/counts/?ids=123',
expect.objectContaining({
method: 'GET',
headers: {'Content-Type': 'application/json'},
credentials: 'same-origin',
body: undefined
}),
);
});