-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add client seo files #759
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
Draft
edupaulos
wants to merge
1
commit into
main
Choose a base branch
from
feat_add_client_seo_files
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/client/src/contents/__fixtures__/seoFiles.fixtures.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { rest, type RestHandler } from 'msw'; | ||
| import type { SEOFiles } from '../types/index.js'; | ||
|
|
||
| const path = '/api/content/v1/seoFiles'; | ||
|
|
||
| const fixtures = { | ||
| get: { | ||
| success: (response: SEOFiles): RestHandler => | ||
| rest.get(path, (_req, res, ctx) => | ||
| res(ctx.status(200), ctx.json(response)), | ||
| ), | ||
| failure: (): RestHandler => | ||
| rest.get(path, (_req, res, ctx) => | ||
| res(ctx.status(404), ctx.json({ message: 'stub error' })), | ||
| ), | ||
| }, | ||
| }; | ||
|
|
||
| export default fixtures; |
11 changes: 11 additions & 0 deletions
11
packages/client/src/contents/__tests__/__snapshots__/getSEOFiles.test.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`SEO Files client getSEOFiles() should handle a client request error 1`] = ` | ||
| Object { | ||
| "code": "-1", | ||
| "message": "stub error", | ||
| "name": "AxiosError", | ||
| "status": 404, | ||
| "transportLayerErrorCode": "ERR_BAD_REQUEST", | ||
| } | ||
| `; |
42 changes: 42 additions & 0 deletions
42
packages/client/src/contents/__tests__/getSEOFiles.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { getSEOFiles } from '../index.js'; | ||
| import { | ||
| seoFilesData, | ||
| seoFilesQuery, | ||
| } from 'tests/__fixtures__/contents/seoFiles.fixtures.mjs'; | ||
| import client from '../../helpers/client/index.js'; | ||
| import fixtures from '../__fixtures__/seoFiles.fixtures.js'; | ||
| import mswServer from '../../../tests/mswServer.js'; | ||
|
|
||
| describe('SEO Files client', () => { | ||
| const expectedConfig = undefined; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('getSEOFiles()', () => { | ||
| const spy = jest.spyOn(client, 'get'); | ||
|
|
||
| it('should handle a client request successfully', async () => { | ||
| mswServer.use(fixtures.get.success(seoFilesData)); | ||
|
|
||
| await expect(getSEOFiles(seoFilesQuery)).resolves.toEqual(seoFilesData); | ||
|
|
||
| expect(spy).toHaveBeenCalledWith( | ||
| '/content/v1/seofiles?hostId=1234&name=siteSEOFiles&page=1&pageSize=60', | ||
| expectedConfig, | ||
| ); | ||
| }); | ||
|
|
||
| it('should handle a client request error', async () => { | ||
| mswServer.use(fixtures.get.failure()); | ||
|
|
||
| await expect(getSEOFiles(seoFilesQuery)).rejects.toMatchSnapshot(); | ||
|
|
||
| expect(spy).toHaveBeenCalledWith( | ||
| '/content/v1/seofiles?hostId=1234&name=siteSEOFiles&page=1&pageSize=60', | ||
| expectedConfig, | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { adaptError } from '../helpers/client/formatError.js'; | ||
| import client from '../helpers/client/index.js'; | ||
| import join from 'proper-url-join'; | ||
| import type { Config } from '../types/index.js'; | ||
| import type { GetSEOFilesQuery, SEOFiles } from './types/seoFiles.types.js'; | ||
|
|
||
| const getSEOFiles = ( | ||
| query: GetSEOFilesQuery, | ||
| config?: Config, | ||
| ): Promise<SEOFiles> => | ||
| client | ||
| .get(join('/content/v1/seofiles', { query }), config) | ||
| .then(response => response.data) | ||
| .catch(error => { | ||
| throw adaptError(error); | ||
| }); | ||
|
|
||
| export default getSEOFiles; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { Config, PagedResponse } from '../../types/index.js'; | ||
|
|
||
| export type GetSEOFiles = ( | ||
| query: GetSEOFilesQuery, | ||
| config?: Config, | ||
| ) => Promise<SEOFiles>; | ||
|
|
||
| export enum SeoFileType { | ||
| None = 'None', | ||
| Sitemap = 'Sitemap', | ||
| Homepage = 'Homepage', | ||
| Pages = 'Pages', | ||
| Posts = 'Posts', | ||
| Products = 'Products', | ||
| Sets = 'Sets', | ||
| Other = 'Other', | ||
| CustomContentTypes = 'CustomContentTypes', | ||
| Categories = 'Categories', | ||
| } | ||
|
|
||
| export type GetSEOFilesQuery = { | ||
| // The name (also named as "slug" on legacy CMS) | ||
| name: string; | ||
| // The hostId | ||
| hostId: number; | ||
| // Number of the page to get, starting at 1. The default is 1. | ||
| page?: number; | ||
| // Size of each page, as a number between 1 and 180. The default is 60. | ||
| pageSize?: number; | ||
| }; | ||
|
|
||
| export type SEOFiles = PagedResponse<SEOFile>; | ||
|
|
||
| export type SEOFile = { | ||
| name: string; | ||
| path?: string; | ||
| uploadDate: string; | ||
| hostId: number; | ||
| subfolderStructure?: string; | ||
| type: SeoFileType; | ||
| content?: string; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/react/src/contents/hooks/__tests__/__fixtures__/useSeoFiles.fixtures.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { type BlackoutError, SeoFileType } from '@farfetch/blackout-client'; | ||
| import { generateSEOFilesHash } from '@farfetch/blackout-redux'; | ||
| import { mockInitialState } from './useSeoMetadata.fixtures.js'; | ||
| import { seoFilesQuery } from 'tests/__fixtures__/contents/seoFiles.fixtures.mjs'; | ||
|
|
||
| const contentSEOFilesHash = generateSEOFilesHash(seoFilesQuery); | ||
|
|
||
| export const mockSEOFilesState = { | ||
| contents: { | ||
| ...mockInitialState.contents, | ||
| seoFiles: { | ||
| error: {}, | ||
| isLoading: {}, | ||
| result: { | ||
| [contentSEOFilesHash]: { | ||
| number: 1, | ||
| totalItems: 1, | ||
| totalPages: 1, | ||
| entries: [ | ||
| { | ||
| name: 'string', | ||
| path: 'string', | ||
| uploadDate: '2023-05-23T17:47:02.770Z', | ||
| hostId: 0, | ||
| subfolderStructure: 'string', | ||
| type: SeoFileType.None, | ||
| content: 'string', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const mockSEOFilesLoadingState = { | ||
| contents: { | ||
| ...mockInitialState.contents, | ||
| seoFiles: { | ||
| isLoading: { [contentSEOFilesHash]: true }, | ||
| error: {}, | ||
| data: undefined, | ||
| isFetched: false, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const mockSEOFilesErrorState = { | ||
| contents: { | ||
| ...mockInitialState.contents, | ||
| seoFiles: { | ||
| isLoading: {}, | ||
| error: { [contentSEOFilesHash]: new Error('Error') as BlackoutError }, | ||
| data: undefined, | ||
| isFetched: true, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const result = { | ||
| error: undefined, | ||
| isLoading: false, | ||
| isFetched: true, | ||
| data: { | ||
| entries: [ | ||
| { | ||
| name: 'string', | ||
| path: 'string', | ||
| uploadDate: '2023-05-23T17:47:02.770Z', | ||
| hostId: 0, | ||
| subfolderStructure: 'string', | ||
| type: SeoFileType.None, | ||
| content: 'string', | ||
| }, | ||
| ], | ||
| number: 1, | ||
| totalItems: 1, | ||
| totalPages: 1, | ||
| }, | ||
| actions: { | ||
| fetch: expect.any(Function), | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.