-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
1,015 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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.