Skip to content

Commit

Permalink
Update: integrates utils from myrmidon
Browse files Browse the repository at this point in the history
  • Loading branch information
pustovitDmytro committed May 5, 2021
1 parent 917022d commit f8bb28c
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 70 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"dot-prop": "5.3.0",
"handlebars": "4.7.7",
"js-yaml": "3.14.1",
"myrmidon": "1.4.4",
"myrmidon": "1.5.1",
"supertest": "4.0.2",
"uuid": "3.4.0"
}
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export {
Chronicle,
Action,
Express,
Axios,
supertest,
axios,
reporters,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Action.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { URL } from 'url';
import uuid from 'uuid';
import { HTTP_STATUS_CODES, DEFAULT_STATUS_CODE } from '../constants';
import { isEmpty } from '../utils/common';
import { isEmpty } from 'myrmidon';

function getQuery(searchParams) {
const query = {};
Expand Down
2 changes: 1 addition & 1 deletion src/requests/Axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class Axios {

return {
...config,
baseURL : `${currentUrl.protocol}//${authPart}${currentUrl.host}`,
baseURL : `${currentUrl.protocol}//${authPart}@${currentUrl.host}`,
url : currentUrl.pathname
};
});
Expand Down
59 changes: 0 additions & 59 deletions src/utils/common.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/utils/decorators.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getMethodNames, isPromise, isFunction } from './common';
import { getMethodNames, isPromise, isFunction } from 'myrmidon';

// TODO: move to myrmidon
function getMethodDescriptor(propertyName, target) {
if (target.hasOwnProperty(propertyName)) {
return Object.getOwnPropertyDescriptor(target, propertyName);
Expand Down
1 change: 0 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './common';
export * from './decorators';
2 changes: 2 additions & 0 deletions tests/Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class Test {
assert.deepOwnInclude(action.response.body, body);
}
}

return action;
}

findAction({ title, group }) {
Expand Down
64 changes: 61 additions & 3 deletions tests/requests/axios.client.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { assert } from 'chai';
import chronicle, { axios } from '../entry';
import chronicle, { axios, Axios } from '../entry';
import { users } from '../mock/fixtures';
import Test from '../Test';
import { mockAppUrl } from '../constants';
import { mockAppUrl, mockAppPort } from '../constants';
import { clone } from 'myrmidon';

suite('Axios');

Expand All @@ -13,6 +14,16 @@ before(async () => {
await factory.setTmpFolder();
});

test('Axios without chronicle', async function () {
const client = new Axios();
const response = await client(`${mockAppUrl}/api/users?limit=10`);
const body = response.data;

assert.isArray(body);
assert.isNotEmpty(body);
assert.deepEqual(body, users);
});

test('Axios usage without context', async function () {
const response = await axios(`${mockAppUrl}/api/users?limit=10`);
const body = response.data;
Expand All @@ -23,7 +34,7 @@ test('Axios usage without context', async function () {
});

test('Axios default function request with chronicle', async function () {
const data = users.find(u => u.id === 2);
const data = clone(users.find(u => u.id === 2));
const context = { title: 'success is', group: 'wrong' };

delete data.id;
Expand All @@ -43,6 +54,53 @@ test('Axios default function request with chronicle', async function () {
});
});

test('Axios native basic auth', async function () {
const data = clone(users.find(u => u.id === 3));
const context = { title: 'native basic auth', group: 'axios' };

delete data.id;

const response = await axios({
method : 'POST',
url : `${mockAppUrl}/api/users`,
data,
auth : { username: 'admin', password: 'password' },
with : context
});

assert.equal(
response.request.getHeader('Authorization'),
'Basic YWRtaW46cGFzc3dvcmQ='
);

assert.deepOwnInclude(response.data, data);

factory.ensureAction(context, {
method : 'POST',
path : '/api/users',
body : data
});
});

test('Axios url basic auth', async function () {
const data = users.find(u => u.id === 2);
const context = { title: 'url basic auth', group: 'axios' };
const response = await axios.with(context).get(`http://admin:password@localhost:${mockAppPort}/api/users/2`);

assert.equal(
response.request.getHeader('Authorization'),
'Basic YWRtaW46cGFzc3dvcmQ='
);

assert.deepOwnInclude(response.data, data);

factory.ensureAction(context, {
method : 'GET',
path : '/api/users/2',
body : data
});
});

test('Axios send xml', async function () {
const context = { title: 'send xml data', group: 'formats' };
const xml = '<language><code>en</code></language>';
Expand Down

0 comments on commit f8bb28c

Please sign in to comment.