-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XM Cloud Proxy] API /api/editing/render endpoint (#1908)
- Loading branch information
1 parent
b4f4b36
commit 60f3ec1
Showing
16 changed files
with
793 additions
and
230 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
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
135 changes: 135 additions & 0 deletions
135
packages/sitecore-jss-proxy/src/middleware/editing/config.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,135 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
import sinon from 'sinon'; | ||
import express from 'express'; | ||
import request from 'supertest'; | ||
import { editingRouter, EditingRouterConfig } from './index'; | ||
import { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss'; | ||
import { EditingRenderEndpointOptions } from './render'; | ||
|
||
describe('editingRouter - /editing/config', () => { | ||
const clientFactory = GraphQLRequestClient.createClientFactory({ | ||
endpoint: 'http://site/?sitecoreContextId=context-id', | ||
}); | ||
|
||
const renderView: sinon.SinonStub = sinon.stub(); | ||
|
||
const renderConfig: EditingRenderEndpointOptions = { | ||
clientFactory, | ||
renderView, | ||
}; | ||
|
||
const defaultOptions: EditingRouterConfig = { | ||
config: { | ||
components: ['component1', 'component2'], | ||
metadata: { | ||
packages: { | ||
foo: '1.0.0', | ||
bar: '2.0.0', | ||
}, | ||
}, | ||
}, | ||
render: renderConfig, | ||
}; | ||
|
||
let app: express.Express; | ||
|
||
beforeEach(() => { | ||
app = express(); | ||
|
||
process.env.JSS_EDITING_SECRET = 'correct'; | ||
}); | ||
|
||
afterEach(() => { | ||
delete process.env.JSS_EDITING_SECRET; | ||
}); | ||
|
||
it('should response 200 status code and return editing config', (done) => { | ||
app.use('/api/editing', editingRouter(defaultOptions)); | ||
|
||
request(app) | ||
.get('/api/editing/config') | ||
.query({ secret: 'correct' }) | ||
.expect( | ||
200, | ||
{ | ||
components: ['component1', 'component2'], | ||
packages: { | ||
foo: '1.0.0', | ||
bar: '2.0.0', | ||
}, | ||
editMode: 'metadata', | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('should response 200 status code and return editing config when components are a map', (done) => { | ||
app.use( | ||
'/api/editing', | ||
editingRouter({ | ||
config: { | ||
components: new Map([ | ||
['component1', true], | ||
['component2', true], | ||
]), | ||
metadata: { | ||
packages: { | ||
foo: '1.0.0', | ||
bar: '2.0.0', | ||
}, | ||
}, | ||
}, | ||
render: renderConfig, | ||
}) | ||
); | ||
|
||
request(app) | ||
.get('/api/editing/config') | ||
.query({ secret: 'correct' }) | ||
.expect( | ||
200, | ||
{ | ||
components: ['component1', 'component2'], | ||
packages: { | ||
foo: '1.0.0', | ||
bar: '2.0.0', | ||
}, | ||
editMode: 'metadata', | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('should response 200 status code and return editing config when custom request path is set', (done) => { | ||
app.use( | ||
'/api/editing', | ||
editingRouter({ | ||
config: { | ||
components: ['component1'], | ||
metadata: { | ||
packages: { | ||
foo: '1.0.0', | ||
}, | ||
}, | ||
path: '/foo/config', | ||
}, | ||
render: renderConfig, | ||
}) | ||
); | ||
|
||
request(app) | ||
.get('/api/editing/foo/config') | ||
.query({ secret: 'correct' }) | ||
.expect( | ||
200, | ||
{ | ||
components: ['component1'], | ||
packages: { | ||
foo: '1.0.0', | ||
}, | ||
editMode: 'metadata', | ||
}, | ||
done | ||
); | ||
}); | ||
}); |
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.