Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Better test #16

Merged
merged 8 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ function del(path, params, callback) {
...rest
}).then(response => {
const nextState = (0, _languageCommon.composeNextState)(state, response);
console.log('nextState', nextState);
if (callback) return callback(nextState);
return nextState;
});
Expand Down
40 changes: 23 additions & 17 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ describe('The get() function', () => {
expect(data).to.eql({ httpStatus: 'OK', message: 'the response' });
expect(references).to.eql([{ triggering: 'event' }]);
expect(counter).to.eql(2);
console.log(nextState);
});
});

Expand Down Expand Up @@ -493,12 +492,14 @@ describe('put', () => {
configuration: {},
data: { name: 'New name' },
};
const finalState = await put('https://www.example.com/api/fake-items/6', {
body: state.data,
})(state);
const finalState = await execute(
put('https://www.example.com/api/fake-items/6', {
body: state.data,
})
)(state);

expect(finalState.statusCode).to.eql(200);
expect(finalState.data.body).to.eql({ name: 'New name' });
expect(finalState.data.body.statusCode).to.eql(200);
expect(finalState.data.body.body).to.eql({ name: 'New name' });
});
});

Expand All @@ -514,19 +515,21 @@ describe('patch', () => {
configuration: {},
data: { name: 'New name', id: 6 },
};
const finalState = await patch('https://www.example.com/api/fake-items/6', {
body: state.data,
})(state);
const finalState = await execute(
patch('https://www.example.com/api/fake-items/6', {
body: state.data,
})
)(state);

expect(finalState.statusCode).to.eql(200);
expect(finalState.data.body).to.eql({ name: 'New name' });
expect(finalState.data.body.statusCode).to.eql(200);
expect(finalState.data.body.body).to.eql({ id: 6, name: 'New name' });
});
});

describe('delete', () => {
before(() => {
testServer.delete('/api/fake-del-items/6').reply(204, function (url, body) {
return {};
return JSON.stringify({});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing significant about this, but it does test that the body is turned back into an object via tryJson.

});
});

Expand All @@ -535,14 +538,17 @@ describe('delete', () => {
configuration: {},
data: {},
};
const finalState = await del(
'https://www.example.com/api/fake-del-items/6',
{
const finalState = await execute(
del('https://www.example.com/api/fake-del-items/6', {
options: {
successCodes: [204],
},
}
})
)(state);
expect(finalState.data.body).to.eql({});

// TODO: fix this interface, if `Utils.tryJson` cleanly converts the
// response body, it won't be under the `body` key. See `put()` example
// above where we have to look inside `data.body.body`.
expect(finalState.data).to.eql({});
});
});