Commit 23d29ed13fd7fbd40e9ec81514e4abfa4bd92cdb

Authored by ABNER SILVA DE OLIVEIRA
1 parent 9a1d573f
Exists in master and in 1 other branch dev-fixes

fixed tests after restangular_service refactory. changes on blog, cms and recent…

…-documents components after refactory
src/app/cms/cms.component.spec.ts
@@ -10,6 +10,7 @@ describe("Components", () => { @@ -10,6 +10,7 @@ describe("Components", () => {
10 let profileServiceMock: any; 10 let profileServiceMock: any;
11 let $state: any; 11 let $state: any;
12 let sweetAlert: any; 12 let sweetAlert: any;
  13 + let profile = { id: 1 };
13 14
14 beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { 15 beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
15 $rootScope = _$rootScope_; 16 $rootScope = _$rootScope_;
@@ -23,10 +24,10 @@ describe("Components", () => { @@ -23,10 +24,10 @@ describe("Components", () => {
23 articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["create"]); 24 articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["create"]);
24 25
25 let getCurrentProfileResponse = $q.defer(); 26 let getCurrentProfileResponse = $q.defer();
26 - getCurrentProfileResponse.resolve({ id: 1 }); 27 + getCurrentProfileResponse.resolve(profile);
27 28
28 let articleCreate = $q.defer(); 29 let articleCreate = $q.defer();
29 - articleCreate.resolve({ path: "path", profile: { identifier: "profile" } }); 30 + articleCreate.resolve({ data: { path: "path", profile: { identifier: "profile" } }});
30 31
31 profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise); 32 profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise);
32 articleServiceMock.create = jasmine.createSpy("create").and.returnValue(articleCreate.promise); 33 articleServiceMock.create = jasmine.createSpy("create").and.returnValue(articleCreate.promise);
@@ -37,7 +38,7 @@ describe("Components", () => { @@ -37,7 +38,7 @@ describe("Components", () => {
37 component.save(); 38 component.save();
38 $rootScope.$apply(); 39 $rootScope.$apply();
39 expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled(); 40 expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled();
40 - expect(articleServiceMock.create).toHaveBeenCalledWith(1, component.article); 41 + expect(articleServiceMock.create).toHaveBeenCalledWith(component.article, profile);
41 done(); 42 done();
42 }); 43 });
43 44
src/app/cms/cms.component.ts
@@ -24,6 +24,7 @@ export class Cms { @@ -24,6 +24,7 @@ export class Cms {
24 this.profileService.getCurrentProfile().then((profile: Profile) => { 24 this.profileService.getCurrentProfile().then((profile: Profile) => {
25 return this.articleService.create(this.article, <any>profile); 25 return this.articleService.create(this.article, <any>profile);
26 }).then((result: noosfero.RestResult<noosfero.Article>) => { 26 }).then((result: noosfero.RestResult<noosfero.Article>) => {
  27 + console.log('RESULT', result);
27 let resultData: noosfero.Article = <noosfero.Article>result.data; 28 let resultData: noosfero.Article = <noosfero.Article>result.data;
28 this.$state.transitionTo('main.profile.page', { page: resultData.path, profile: resultData.profile.identifier }); 29 this.$state.transitionTo('main.profile.page', { page: resultData.path, profile: resultData.profile.identifier });
29 this.SweetAlert.swal({ 30 this.SweetAlert.swal({
src/app/components/noosfero-articles/blog/blog.component.spec.ts
@@ -101,11 +101,11 @@ describe(&quot;Blog Component&quot;, () =&gt; { @@ -101,11 +101,11 @@ describe(&quot;Blog Component&quot;, () =&gt; {
101 title: 'The article test' 101 title: 'The article test'
102 }]; 102 }];
103 103
104 - (<any>articles)['_headers'] = { total: 1 }; 104 + let result = { data: articles, headers: (name: string) => { return 1; } };
105 105
106 // defining a mock result to articleService.getChildren method 106 // defining a mock result to articleService.getChildren method
107 articleService.getChildren = (article_id: number, filters: {}) => { 107 articleService.getChildren = (article_id: number, filters: {}) => {
108 - return promiseResultTemplate(articles); 108 + return promiseResultTemplate(result);
109 }; 109 };
110 110
111 createComponentFromClass(BlogContainerComponent).then((fixture) => { 111 createComponentFromClass(BlogContainerComponent).then((fixture) => {
src/app/components/noosfero-articles/blog/blog.component.ts
@@ -34,7 +34,7 @@ export class ArticleBlog { @@ -34,7 +34,7 @@ export class ArticleBlog {
34 this.articleService 34 this.articleService
35 .getChildren(this.article, filters) 35 .getChildren(this.article, filters)
36 .then((result: noosfero.RestResult<noosfero.Article>) => { 36 .then((result: noosfero.RestResult<noosfero.Article>) => {
37 - this.totalPosts = <number>(<any>result.data)["_headers"]["total"]; 37 + this.totalPosts = <number>result.headers("total");
38 this.posts = <noosfero.Article[]> result.data; 38 this.posts = <noosfero.Article[]> result.data;
39 }); 39 });
40 } 40 }
src/app/components/noosfero-blocks/recent-documents/recent-documents.component.spec.ts
@@ -18,7 +18,7 @@ describe(&quot;Components&quot;, () =&gt; { @@ -18,7 +18,7 @@ describe(&quot;Components&quot;, () =&gt; {
18 new Provider('ArticleService', { 18 new Provider('ArticleService', {
19 useValue: { 19 useValue: {
20 getByProfile: (profileId: number, filters: any): any => { 20 getByProfile: (profileId: number, filters: any): any => {
21 - return Promise.resolve({ articles: [{ name: "article1" }] }); 21 + return Promise.resolve({ data: [{ name: "article1" }] , headers: (name: string) => {return name;}});
22 } 22 }
23 } 23 }
24 }), 24 }),
src/lib/ng-noosfero-api/http/article.service.ts
1 import { Injectable, Inject } from "ng-forward"; 1 import { Injectable, Inject } from "ng-forward";
2 import {RestangularService} from "./restangular_service"; 2 import {RestangularService} from "./restangular_service";
  3 +import {ProfileService} from "./profile.service";
  4 +
3 @Injectable() 5 @Injectable()
4 -@Inject("Restangular", "$q") 6 +@Inject("Restangular", "$q", "$log", ProfileService)
5 7
6 export class ArticleService extends RestangularService<noosfero.Article> { 8 export class ArticleService extends RestangularService<noosfero.Article> {
7 9
8 - constructor(Restangular: restangular.IService, $q: ng.IQService, $log: ng.ILogService) { 10 + constructor(Restangular: restangular.IService, $q: ng.IQService, $log: ng.ILogService, protected profileService: ProfileService) {
9 super(Restangular, $q, $log); 11 super(Restangular, $q, $log);
10 } 12 }
11 13
@@ -57,7 +59,8 @@ export class ArticleService extends RestangularService&lt;noosfero.Article&gt; { @@ -57,7 +59,8 @@ export class ArticleService extends RestangularService&lt;noosfero.Article&gt; {
57 // TODO -> change all Restangular services to this approach "Return promise to a specific type" 59 // TODO -> change all Restangular services to this approach "Return promise to a specific type"
58 // it makes easy consume the service 60 // it makes easy consume the service
59 getByProfile<T>(profile: noosfero.Profile, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> { 61 getByProfile<T>(profile: noosfero.Profile, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> {
60 - return this.list(profile); 62 + let profileElement = this.profileService.get(<number>profile.id);
  63 + return this.list(profileElement, params);
61 } 64 }
62 65
63 getChildren<T>(article: noosfero.Article, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> { 66 getChildren<T>(article: noosfero.Article, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> {