Skip to content

Commit

Permalink
Merge pull request #34 from mangei/MG/relativeUrls
Browse files Browse the repository at this point in the history
make the api url relative, such that the application works if it is d…
  • Loading branch information
tsalzinger committed Oct 6, 2015
2 parents 4f7a479 + 9a1aa43 commit b02fa50
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/javascript/service/cat-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ function CatApiServiceProvider() {
*/
angular
.module('cat.service.api', ['cat.service.conversion', 'cat.service.search'])
.constant('CAT_API_SERVICE_DEFAULTS', {endpointUrlPrefix: '/api/'})
.constant('CAT_API_SERVICE_DEFAULTS', {endpointUrlPrefix: 'api/'})
.provider('catApiService', CatApiServiceProvider);

/**
Expand Down
24 changes: 12 additions & 12 deletions src/test/javascript/service/cat-api-service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Api Service', function () {
});

it('should return a converted object', function () {
$httpBackend.expectGET('/api/test/' + testData[0].id).respond(testData[0]);
$httpBackend.expectGET('api/test/' + testData[0].id).respond(testData[0]);
catApiService.test.get(testData[0].id).then(function (result) {
expect(result).toBeDefined();
cat.util.test.expectToEqualConverted(result, testData[0]);
Expand All @@ -52,7 +52,7 @@ describe('Api Service', function () {

it('should return a paginated result if a PagedResultDTO is returned by the server', function () {
var serverData = {totalCount: 2, elements: testData};
$httpBackend.expectGET('/api/test?page=0&size=100').respond(serverData);
$httpBackend.expectGET('api/test?page=0&size=100').respond(serverData);
catApiService.test.list(new window.cat.SearchRequest()).then(function (result) {
expect(result).toBeDefined();
expect(result.totalCount).toBe(2);
Expand All @@ -63,7 +63,7 @@ describe('Api Service', function () {
});

it('should return a list of objects if the server response is not paginated', function () {
$httpBackend.expectGET('/api/test').respond(testData);
$httpBackend.expectGET('api/test').respond(testData);
catApiService.test.list().then(function (result) {
expect(result).toBeDefined();
expect(result.length).toBe(2);
Expand All @@ -75,7 +75,7 @@ describe('Api Service', function () {
it('should post an object without id', function () {
var clientData = {name: 'NewTestObject'};
var serverData = {id: 100, name: 'NewTestObject'};
$httpBackend.expectPOST('/api/test', clientData).respond(serverData);
$httpBackend.expectPOST('api/test', clientData).respond(serverData);
catApiService.test.save(clientData).then(function (result) {
cat.util.test.expectToEqualConverted(result, new cat.util.test.Model(serverData));
});
Expand All @@ -84,47 +84,47 @@ describe('Api Service', function () {

it('should update an object with id', function () {
var data = {id: 100, name: 'NewTestObject'};
$httpBackend.expectPUT('/api/test/100', data).respond(data);
$httpBackend.expectPUT('api/test/100', data).respond(data);
catApiService.test.save(data).then(function (result) {
cat.util.test.expectToEqualConverted(result, data);
});
$httpBackend.flush();
});

it('should delete an object', function () {
$httpBackend.expectDELETE('/api/test/100').respond(200);
$httpBackend.expectDELETE('api/test/100').respond(200);
catApiService.test.remove(100).then(function (response) {
expect(response.status).toBe(200);
});
$httpBackend.flush();
});

it('should call custom GET url', function () {
$httpBackend.expectGET('/api/test/customGET').respond(200);
$httpBackend.expectGET('api/test/customGET').respond(200);
catApiService.test.custom.get('customGET').then(function (response) {
expect(response.status).toBe(200);
});
$httpBackend.flush();
});

it('should call custom GET url with search request', function () {
$httpBackend.expectGET('/api/test/customGET?page=0&size=100').respond(200);
$httpBackend.expectGET('api/test/customGET?page=0&size=100').respond(200);
catApiService.test.custom.get('customGET', new window.cat.SearchRequest()).then(function (response) {
expect(response.status).toBe(200);
});
$httpBackend.flush();
});

it('should call custom POST url', function () {
$httpBackend.expectPOST('/api/test/customPOST', {name: 'NewTestObject'}).respond(200);
$httpBackend.expectPOST('api/test/customPOST', {name: 'NewTestObject'}).respond(200);
catApiService.test.custom.post('customPOST', {name: 'NewTestObject'}).then(function (response) {
expect(response.status).toBe(200);
});
$httpBackend.flush();
});

it('should call custom PUT url', function () {
$httpBackend.expectPUT('/api/test/customPUT', {id: 100, name: 'NewTestObject'}).respond(200);
$httpBackend.expectPUT('api/test/customPUT', {id: 100, name: 'NewTestObject'}).respond(200);
catApiService.test.custom.put('customPUT', {id: 100, name: 'NewTestObject'}).then(function (response) {
expect(response.status).toBe(200);
});
Expand All @@ -141,7 +141,7 @@ describe('Api Service', function () {
expect(endpoint1).toBe(endpoint2);

// test dynamic endpoint functionality
$httpBackend.expectGET('/api/test/' + testData[0].id).respond(testData[0]);
$httpBackend.expectGET('api/test/' + testData[0].id).respond(testData[0]);
endpoint2.get(testData[0].id).then(function (result) {
expect(result).toBeDefined();
cat.util.test.expectToEqualConverted(result, testData[0]);
Expand All @@ -152,7 +152,7 @@ describe('Api Service', function () {
it('should allow endpoint children', function () {
var user2 = catApiService.user.res(2);

$httpBackend.expectGET('/api/user/2/friend').respond(testData);
$httpBackend.expectGET('api/user/2/friend').respond(testData);
user2.friend.list().then(function (result) {
expect(result).toBeDefined();
expect(result.length).toBe(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('CatListDataLoadingService', function () {

it('should update the properties', function () {
var paginatedTestData = {totalCount: 2, elements: testData};
$httpBackend.expectGET('/api/test?page=0&size=100').respond(paginatedTestData);
$httpBackend.expectGET('api/test?page=0&size=100').respond(paginatedTestData);
catListDataLoadingService.load(catApiService.test, new window.cat.SearchRequest()).then(function (result) {
expect(result.count).toBe(2);
expect(result.firstResult).toBe(1);
Expand All @@ -53,7 +53,7 @@ describe('CatListDataLoadingService', function () {

it('should update the properties and use sorting settings', function () {
var paginatedTestData = {totalCount: 2, elements: testData};
$httpBackend.expectGET('/api/test?page=0&size=100&sort=name:desc').respond(paginatedTestData);
$httpBackend.expectGET('api/test?page=0&size=100&sort=name:desc').respond(paginatedTestData);
catListDataLoadingService.resolve('test', {property: 'name', isDesc: true}).then(function (result) {
expect(result.count).toBe(2);
expect(result.firstResult).toBe(1);
Expand Down

0 comments on commit b02fa50

Please sign in to comment.