Skip to content

Commit

Permalink
Release 2.0.0-rc.8.1 ♨️
Browse files Browse the repository at this point in the history
- Hot Fix: #82
  • Loading branch information
Jonathan Casarrubias committed Aug 8, 2016
1 parent 470c4b1 commit 00f0427
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 37 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This file is created to keep history of the LoopBack SDK Builder, it does not consider or keeps any history of its parent module `loopback-sdk-angular`.

## Release 2.0.0-rc.8.1

- Hot Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/82

## Release 2.0.0-rc.8

- Fix: https://github.com/jonathan-casarrubias/loopback-sdk-builder/issues/81
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ You don't have to manually write any static code.

````sh
$ cd to/api/project
$ npm install --save-dev [email protected]
$ npm install --save-dev [email protected].1
````

# LoopBack SDK CLI Options
Expand Down
39 changes: 31 additions & 8 deletions lib/angular2/shared/services/core/base.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,36 @@ export abstract class BaseLoopBackApi {
* @param any routeParams Values of url parameters
* @param any urlParams Parameters for building url (filter and other)
* @param any postBody Request postBody
* @param boolean isio Request socket connection
* @param boolean isio Request socket connection (When IO is enabled)
*/
public request(method: string, url: string, routeParams: any = {}, urlParams: any = {}, postBody: any = null<% if ( isIo === 'enabled' ){ -%>, isio: boolean = false<% } -%>) {
public request(
method : string,
url : string,
routeParams : any = {},
urlParams : any = {},
postBody : any = null<% if ( isIo === 'enabled' ){ -%>,
isio : boolean = false<% }
-%>

) {

let headers = new Headers();
headers.append('Content-Type', 'application/json');

if (this.auth.getAccessTokenId()) {
headers.append('Authorization', LoopBackConfig.getAuthPrefix() + this.auth.getAccessTokenId());
headers.append(
'Authorization',
LoopBackConfig.getAuthPrefix() + this.auth.getAccessTokenId()
);
}

let requestUrl = url;
let key: string;
for (key in routeParams) {
requestUrl = requestUrl.replace(new RegExp(":" + key + "(\/|$)", "g"), routeParams[key] + "$1");
requestUrl = requestUrl.replace(
new RegExp(":" + key + "(\/|$)", "g"),
routeParams[key] + "$1"
);
}

<% if ( isIo === 'enabled' ){ -%>
Expand All @@ -73,11 +89,18 @@ export abstract class BaseLoopBackApi {
socket.on(event, res => subject.next(res));
return subject.asObservable();
} else {<% } -%>
// Body fix for built in remote methods using "data" or "credentials" that are the actual body
// Custom remote method properties are different and need to be wrapped into a body object
// Body fix for built in remote methods using "data", "options" or "credentials
// that are the actual body, Custom remote method properties are different and need
// to be wrapped into a body object
let body: any;
if (typeof postBody === 'object' && (postBody.data || postBody.credentials) && Object.keys(postBody).length === 1) {
body = (postBody.data) ? postBody.data : postBody.credentials;
if (
typeof postBody === 'object' &&
(postBody.data || postBody.credentials || postBody.options) &&
Object.keys(postBody).length === 1
) {
body = postBody.data ? postBody.data :
postBody.options ? postBody.options :
postBody.credentials;
} else {
body = postBody;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loopback-sdk-builder",
"version": "2.0.0-rc.8",
"version": "2.0.0-rc.8.1",
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
"bin": {
"lb-ng": "bin/lb-ng",
Expand Down
25 changes: 12 additions & 13 deletions tests/angular2/src/app/room-service.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
LoopBackConfig.setBaseURL('http://127.0.0.1:3000');
LoopBackConfig.setApiVersion('api');

describe('UserService Service', () => {
describe('RoomService Tests', () => {
beforeEachProviders(() => [API_PROVIDERS]);

it('should contain persisted model methods',
Expand All @@ -39,7 +39,7 @@ describe('UserService Service', () => {
room.name = Date.now().toString();

return roomApi.create(room)
.subscribe((room: Room) => expect(room.id).toBeTruthy());
.subscribe((instance: Room) => expect(instance.id).toBeTruthy());
})
));

Expand All @@ -51,7 +51,7 @@ describe('UserService Service', () => {
.subscribe((createdRoom: Room) => {
expect(createdRoom.id).toBeTruthy();
roomApi.findById(createdRoom.id)
.subscribe((foundRoom: Room) => expect(foundRoom.id).toBe(createdRoom.id))
.subscribe((foundRoom: Room) => expect(foundRoom.id).toBe(createdRoom.id));
});
})
));
Expand All @@ -60,12 +60,12 @@ describe('UserService Service', () => {
async(inject([RoomApi], (roomApi: RoomApi) => {
let room: Room = new Room();
room.name = Date.now().toString();
return roomApi.create(room).subscribe((room: Room) =>
roomApi.createMessages(room.id, {
return roomApi.create(room).subscribe((instance: Room) =>
roomApi.createMessages(instance.id, {
text: 'HelloRoom'
}).subscribe(message => {
expect(message.id).toBeTruthy();
expect(message.roomId).toBe(room.id);
expect(message.roomId).toBe(instance.id);
})
);
})
Expand All @@ -77,12 +77,12 @@ describe('UserService Service', () => {
room.name = Date.now().toString();
let message = { text: 'Hello Room with Query' };
return roomApi.create(room)
.subscribe((room: Room) => roomApi.createMessages(room.id, message)
.subscribe(message => roomApi.getMessages(room.id, { where: message })
.subscribe((instance: Room) => roomApi.createMessages(instance.id, message)
.subscribe(messageInstance => roomApi.getMessages(instance.id, { where: message })
.subscribe(messages => {
expect(messages.length).toBe(1);
let msg = messages.pop();
expect(msg.text).toBe(message.text);
expect(msg.text).toBe(messageInstance.text);
})));
})
));
Expand All @@ -92,7 +92,7 @@ describe('UserService Service', () => {
let params = ['Hi', 'My Name Is', 'What'];
return roomApi.greetRoute(params[0], params[1], params[2])
.subscribe((result: {greeting: string}) => {
expect(result.greeting).toBe(params.join(':'))
expect(result.greeting).toBe(params.join(':'));
});
})
));
Expand All @@ -102,7 +102,7 @@ describe('UserService Service', () => {
let params = ['Hi', 'My Name Is', 'Who'];
return roomApi.greetGet(params[0], params[1], params[2])
.subscribe((result: {greeting: string}) => {
expect(result.greeting).toBe(params.join(':'))
expect(result.greeting).toBe(params.join(':'));
});
})
));
Expand All @@ -112,9 +112,8 @@ describe('UserService Service', () => {
let params = ['Hi', 'My Name Is', 'Slim Shady!!'];
return roomApi.greetPost(params[0], params[1], params[2])
.subscribe((result: {greeting: string}) => {
expect(result.greeting).toBe(params.join(':'))
expect(result.greeting).toBe(params.join(':'));
});
})
));

});
2 changes: 1 addition & 1 deletion tests/angular2/src/app/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './sdk/index';
export * from './sdk/index';
37 changes: 29 additions & 8 deletions tests/angular2/src/app/shared/sdk/services/core/base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,47 @@ export abstract class BaseLoopBackApi {
* @param any routeParams Values of url parameters
* @param any urlParams Parameters for building url (filter and other)
* @param any postBody Request postBody
* @param boolean isio Request socket connection
* @param boolean isio Request socket connection (When IO is enabled)
*/
public request(method: string, url: string, routeParams: any = {}, urlParams: any = {}, postBody: any = null) { let headers = new Headers();
public request(
method : string,
url : string,
routeParams : any = {},
urlParams : any = {},
postBody : any = null
) {

let headers = new Headers();
headers.append('Content-Type', 'application/json');

if (this.auth.getAccessTokenId()) {
headers.append('Authorization', LoopBackConfig.getAuthPrefix() + this.auth.getAccessTokenId());
headers.append(
'Authorization',
LoopBackConfig.getAuthPrefix() + this.auth.getAccessTokenId()
);
}

let requestUrl = url;
let key: string;
for (key in routeParams) {
requestUrl = requestUrl.replace(new RegExp(":" + key + "(\/|$)", "g"), routeParams[key] + "$1");
requestUrl = requestUrl.replace(
new RegExp(":" + key + "(\/|$)", "g"),
routeParams[key] + "$1"
);
}

// Body fix for built in remote methods using "data" or "credentials" that are the actual body
// Custom remote method properties are different and need to be wrapped into a body object
// Body fix for built in remote methods using "data", "options" or "credentials
// that are the actual body, Custom remote method properties are different and need
// to be wrapped into a body object
let body: any;
if (typeof postBody === 'object' && (postBody.data || postBody.credentials) && Object.keys(postBody).length === 1) {
body = (postBody.data) ? postBody.datapostBody.credentials;
if (
typeof postBody === 'object' &&
(postBody.data || postBody.credentials || postBody.options) &&
Object.keys(postBody).length === 1
) {
body = postBody.data ? postBody.data :
postBody.options ? postBody.options :
postBody.credentials;
} else {
body = postBody;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/angular2/src/app/user-service.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
LoopBackConfig.setBaseURL('http://127.0.0.1:3000');
LoopBackConfig.setApiVersion('api');

describe('UserService Service', () => {
describe('UserService Tests', () => {
beforeEachProviders(() => [API_PROVIDERS]);

it('should contain authentication methods',
Expand All @@ -38,7 +38,7 @@ describe('UserService Service', () => {
user.email = Date.now() + '@test.com';
user.password = 'test';
return userApi.create(user)
.subscribe((user: User) => expect(user.id).toBeTruthy());
.subscribe((instance: User) => expect(instance.id).toBeTruthy());
})
));

Expand Down Expand Up @@ -87,9 +87,9 @@ describe('UserService Service', () => {
user.password = 'test';
return userApi.create(user)
.subscribe((instance: User) => userApi.login(user)
.subscribe((token: AccessTokenInterface) =>
userApi.getCurrent().subscribe((user: User) => {
expect(user.id).toBe(instance.id);
.subscribe((token: AccessTokenInterface) =>
userApi.getCurrent().subscribe((current: User) => {
expect(current.id).toBe(instance.id);
}))
);
})));
Expand Down

0 comments on commit 00f0427

Please sign in to comment.