Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
maint(core): Formatting code
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhousley committed Dec 12, 2018
1 parent 95c9b52 commit 582c084
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 65 deletions.
113 changes: 75 additions & 38 deletions libs/core/src/lib/axios-angular-adapter.service.spec.ts
Expand Up @@ -138,8 +138,8 @@ describe('AxiosAngularAdapterService', () => {
[chance.guid()]: chance.word()
};
const paramString = Object.keys(params)
.map(param => `${param}=${params[param]}`)
.join('&');
.map(param => `${param}=${params[param]}`)
.join('&');

// Act
service.adapter({ url, method, params });
Expand All @@ -166,8 +166,8 @@ describe('AxiosAngularAdapterService', () => {
[chance.guid()]: chance.word()
};
const paramString = Object.keys(params)
.map(param => `${param}=${params[param]}`)
.join('&');
.map(param => `${param}=${params[param]}`)
.join('&');
const expected = {
[chance.guid()]: chance.word(),
[chance.guid()]: chance.word(),
Expand All @@ -177,7 +177,8 @@ describe('AxiosAngularAdapterService', () => {
};

// Act / Assert
service.adapter({ url, method, params })
service
.adapter({ url, method, params })
.then(response => {
expect(response.data).toEqual(expected);
done();
Expand All @@ -199,12 +200,13 @@ describe('AxiosAngularAdapterService', () => {
[chance.guid()]: chance.word()
};
const paramString = Object.keys(params)
.map(param => `${param}=${params[param]}`)
.join('&');
.map(param => `${param}=${params[param]}`)
.join('&');
const expected = chance.integer({ min: 200, max: 207 });

// Act / Assert
service.adapter({ url, method, params })
service
.adapter({ url, method, params })
.then(response => {
expect(response.status).toEqual(expected);
done();
Expand All @@ -226,12 +228,13 @@ describe('AxiosAngularAdapterService', () => {
[chance.guid()]: chance.word()
};
const paramString = Object.keys(params)
.map(param => `${param}=${params[param]}`)
.join('&');
.map(param => `${param}=${params[param]}`)
.join('&');
const expected = chance.word();

// Act / Assert
service.adapter({ url, method, params })
service
.adapter({ url, method, params })
.then(response => {
expect(response.statusText).toEqual(expected);
done();
Expand All @@ -253,8 +256,8 @@ describe('AxiosAngularAdapterService', () => {
[chance.guid()]: chance.word()
};
const paramString = Object.keys(params)
.map(param => `${param}=${params[param]}`)
.join('&');
.map(param => `${param}=${params[param]}`)
.join('&');
const expected = {
[chance.guid()]: chance.word(),
[chance.guid()]: chance.word(),
Expand All @@ -264,7 +267,8 @@ describe('AxiosAngularAdapterService', () => {
};

// Act / Assert
service.adapter({ url, method, params })
service
.adapter({ url, method, params })
.then(response => {
expect(response.headers).toEqual(expected);
done();
Expand All @@ -286,12 +290,13 @@ describe('AxiosAngularAdapterService', () => {
[chance.guid()]: chance.word()
};
const paramString = Object.keys(params)
.map(param => `${param}=${params[param]}`)
.join('&');
.map(param => `${param}=${params[param]}`)
.join('&');
const expected = { url, method, params };

// Act / Assert
service.adapter({ url, method, params })
service
.adapter({ url, method, params })
.then(response => {
expect(response.config).toEqual(expected);
done();
Expand All @@ -313,11 +318,12 @@ describe('AxiosAngularAdapterService', () => {
[chance.guid()]: chance.word()
};
const paramString = Object.keys(params)
.map(param => `${param}=${params[param]}`)
.join('&');
.map(param => `${param}=${params[param]}`)
.join('&');

// Act / Assert
service.adapter({ url, method, params })
service
.adapter({ url, method, params })
.then(response => {
expect(response.request).toBeInstanceOf(Observable);
done();
Expand All @@ -342,7 +348,8 @@ describe('AxiosAngularAdapterService', () => {
};

// Act / Assert
service.adapter({ url, method })
service
.adapter({ url, method })
.then(() => {
done('Request should have failed');
})
Expand All @@ -351,7 +358,10 @@ describe('AxiosAngularAdapterService', () => {
done();
});
const req = httpMock.expectOne(url);
req.flush(expected, { status: chance.integer({ min: 400, max: 407 }), statusText: chance.word() });
req.flush(expected, {
status: chance.integer({ min: 400, max: 407 }),
statusText: chance.word()
});
});

it('should include the response status in the returned object', done => {
Expand All @@ -361,7 +371,8 @@ describe('AxiosAngularAdapterService', () => {
const expected = chance.integer({ min: 400, max: 407 });

// Act / Assert
service.adapter({ url, method })
service
.adapter({ url, method })
.then(() => {
done('Request should have failed');
})
Expand All @@ -380,7 +391,8 @@ describe('AxiosAngularAdapterService', () => {
const expected = chance.word();

// Act / Assert
service.adapter({ url, method })
service
.adapter({ url, method })
.then(() => {
done('Request should have failed');
})
Expand All @@ -389,7 +401,10 @@ describe('AxiosAngularAdapterService', () => {
done();
});
const req = httpMock.expectOne(url);
req.flush('', { status: chance.integer({ min: 400, max: 407 }), statusText: expected });
req.flush('', {
status: chance.integer({ min: 400, max: 407 }),
statusText: expected
});
});

it('should include the response headers in the returned object', done => {
Expand All @@ -405,7 +420,8 @@ describe('AxiosAngularAdapterService', () => {
};

// Act / Assert
service.adapter({ url, method })
service
.adapter({ url, method })
.then(() => {
done('Request should have failed');
})
Expand All @@ -414,7 +430,11 @@ describe('AxiosAngularAdapterService', () => {
done();
});
const req = httpMock.expectOne(url);
req.flush('', { status: chance.integer({ min: 400, max: 407 }), statusText: chance.word(), headers: expected });
req.flush('', {
status: chance.integer({ min: 400, max: 407 }),
statusText: chance.word(),
headers: expected
});
});

it('should include the request config in the returned object', done => {
Expand All @@ -424,7 +444,8 @@ describe('AxiosAngularAdapterService', () => {
const expected = { url, method };

// Act / Assert
service.adapter({ url, method })
service
.adapter({ url, method })
.then(() => {
done('Request should have failed');
})
Expand All @@ -435,7 +456,10 @@ describe('AxiosAngularAdapterService', () => {
done();
});
const req = httpMock.expectOne(url);
req.flush('', { status: chance.integer({ min: 400, max: 407 }), statusText: chance.word() });
req.flush('', {
status: chance.integer({ min: 400, max: 407 }),
statusText: chance.word()
});
});

it('should include the request observable in the returned object', done => {
Expand All @@ -444,7 +468,8 @@ describe('AxiosAngularAdapterService', () => {
const method = 'get';

// Act / Assert
service.adapter({ url, method })
service
.adapter({ url, method })
.then(() => {
done('Request should have failed');
})
Expand All @@ -455,7 +480,10 @@ describe('AxiosAngularAdapterService', () => {
done();
});
const req = httpMock.expectOne(url);
req.flush('', { status: chance.integer({ min: 400, max: 407 }), statusText: chance.word() });
req.flush('', {
status: chance.integer({ min: 400, max: 407 }),
statusText: chance.word()
});
});

it('should include the response code in the returned object', done => {
Expand All @@ -464,7 +492,8 @@ describe('AxiosAngularAdapterService', () => {
const method = 'get';

// Act / Assert
service.adapter({ url, method })
service
.adapter({ url, method })
.then(() => {
done('Request should have failed');
})
Expand All @@ -473,7 +502,10 @@ describe('AxiosAngularAdapterService', () => {
done();
});
const req = httpMock.expectOne(url);
req.flush('', { status: chance.integer({ min: 400, max: 407 }), statusText: chance.word() });
req.flush('', {
status: chance.integer({ min: 400, max: 407 }),
statusText: chance.word()
});
});
});

Expand All @@ -482,14 +514,15 @@ describe('AxiosAngularAdapterService', () => {
// Arrange
const url = chance.url();
const method = 'get';
const status = chance.integer({ min: 200, max: 207 })
const status = chance.integer({ min: 200, max: 207 });
const validateStatus = jest.fn(() => true);

// Act / Assert
service.adapter({ url, method, validateStatus })
service
.adapter({ url, method, validateStatus })
.then(() => {
expect(validateStatus).toHaveBeenCalledTimes(1);
expect(validateStatus).toHaveBeenCalledWith(status)
expect(validateStatus).toHaveBeenCalledWith(status);
done();
})
.catch(error => {
Expand All @@ -506,7 +539,8 @@ describe('AxiosAngularAdapterService', () => {
const validateStatus = jest.fn(() => false);

// Act / Assert
service.adapter({ url, method, validateStatus })
service
.adapter({ url, method, validateStatus })
.then(() => {
done('Request should have failed');
})
Expand All @@ -518,7 +552,10 @@ describe('AxiosAngularAdapterService', () => {
done();
});
const req = httpMock.expectOne(url);
req.flush('', { status: chance.integer({ min: 200, max: 207 }), statusText: chance.word() });
req.flush('', {
status: chance.integer({ min: 200, max: 207 }),
statusText: chance.word()
});
});
});
});

0 comments on commit 582c084

Please sign in to comment.