Skip to content

Commit

Permalink
Body can be empty in POST request in actions (#1072)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored Feb 9, 2021
1 parent 1d8005c commit c6170fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/lib/scene/scene.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ const actionsFunc = {
}
});
const urlWithVariables = Handlebars.compile(action.url)(scope);
const bodyWithVariables = Handlebars.compile(action.body)(scope);
// body can be empty
const bodyWithVariables = action.body ? Handlebars.compile(action.body)(scope) : undefined;
const response = await self.http.request(
action.method,
urlWithVariables,
Expand Down
27 changes: 27 additions & 0 deletions server/test/lib/scene/scene.executeActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,33 @@ describe('scene.executeActions', () => {
);
assert.calledWith(http.request, 'post', 'http://test.test', { toto: 'toto' }, { authorization: 'token' });
});
it('should execute action http.request with empty body', async () => {
const stateManager = new StateManager(event);
const http = {
request: fake.resolves({ success: true }),
};
const scope = {};
await executeActions(
{ stateManager, event, http },
[
[
{
type: ACTIONS.HTTP.REQUEST,
method: 'post',
url: 'http://test.test',
headers: [
{
key: 'authorization',
value: 'token',
},
],
},
],
],
scope,
);
assert.calledWith(http.request, 'post', 'http://test.test', undefined, { authorization: 'token' });
});
it('should abort scene, condition is not verified', async () => {
const stateManager = new StateManager(event);
stateManager.setState('deviceFeature', 'my-device-feature', {
Expand Down

0 comments on commit c6170fe

Please sign in to comment.