-
Notifications
You must be signed in to change notification settings - Fork 19
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
1 parent
c3cf144
commit d96e10c
Showing
12 changed files
with
146 additions
and
18 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
84 changes: 84 additions & 0 deletions
84
packages/next/src/rsc/data/queries/__tests__/prepareQuery.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,84 @@ | ||
import { setHeadstartWPConfig } from '@headstartwp/core'; | ||
import { prepareQuery } from '../prepareQuery'; | ||
|
||
describe('prepareQuery', () => { | ||
beforeAll(() => { | ||
setHeadstartWPConfig({ | ||
sites: [ | ||
{ | ||
sourceUrl: 'https://backend1.com', | ||
hostUrl: 'https://site1.com', | ||
}, | ||
{ | ||
sourceUrl: 'https://backend2.com', | ||
hostUrl: 'https://site2.com', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('converts path to string', () => { | ||
expect( | ||
prepareQuery({ routeParams: { path: ['2020', '05', '07', 'post-name'] } }), | ||
).toMatchObject({ | ||
path: '/2020/05/07/post-name', | ||
}); | ||
|
||
expect(prepareQuery({ routeParams: { path: '/2020/05/07/post-name' } })).toMatchObject({ | ||
path: '/2020/05/07/post-name', | ||
}); | ||
}); | ||
|
||
it('default headers to no-store', () => { | ||
expect(prepareQuery({})).toMatchObject({ | ||
options: { | ||
headers: { | ||
cache: 'no-store', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('gets site config based on site param', () => { | ||
expect( | ||
prepareQuery({ | ||
routeParams: { site: 'site1.com' }, | ||
}), | ||
).toMatchObject({ | ||
config: { | ||
sourceUrl: 'https://backend1.com', | ||
hostUrl: 'https://site1.com', | ||
}, | ||
}); | ||
|
||
expect( | ||
prepareQuery({ | ||
routeParams: { site: 'site2.com' }, | ||
}), | ||
).toMatchObject({ | ||
config: { | ||
sourceUrl: 'https://backend2.com', | ||
hostUrl: 'https://site2.com', | ||
}, | ||
}); | ||
|
||
expect( | ||
prepareQuery({ | ||
routeParams: { site: 'site2.com', path: ['post-name'] }, | ||
}), | ||
).toMatchObject({ | ||
path: '/post-name', | ||
config: { | ||
sourceUrl: 'https://backend2.com', | ||
hostUrl: 'https://site2.com', | ||
}, | ||
}); | ||
|
||
// this one should throw | ||
expect(() => | ||
prepareQuery({ | ||
routeParams: { site: 'site3.com', path: ['post-name'] }, | ||
}), | ||
).toThrow('Sub site not found, make sure to add site3.com to headstartwp.config.js'); | ||
}); | ||
}); |
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,16 @@ | ||
import { queryPost } from '../queryPost'; | ||
|
||
describe('queryPosts', () => { | ||
it('fetches posts', async () => { | ||
const { data } = await queryPost({ | ||
routeParams: { | ||
path: ['2020', '05', '07', 'modi-qui-dignissimos-sed-assumenda-sint-iusto'], | ||
}, | ||
params: { | ||
matchCurrentPath: false, | ||
}, | ||
}); | ||
|
||
expect(data.post.slug).toBe('modi-qui-dignissimos-sed-assumenda-sint-iusto'); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/next/src/rsc/data/queries/__tests__/queryPosts.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,13 @@ | ||
import { queryPosts } from '../queryPosts'; | ||
|
||
describe('queryPosts', () => { | ||
it('fetches posts', async () => { | ||
const { data } = await queryPosts({ | ||
params: { | ||
per_page: 2, | ||
}, | ||
}); | ||
|
||
expect(data.posts).toHaveLength(2); | ||
}); | ||
}); |
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
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
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