Commit 23d29ed13fd7fbd40e9ec81514e4abfa4bd92cdb
1 parent
9a1d573f
Exists in
master
and in
31 other branches
fixed tests after restangular_service refactory. changes on blog, cms and recent…
…-documents components after refactory
Showing
6 changed files
with
15 additions
and
10 deletions
Show diff stats
src/app/cms/cms.component.spec.ts
... | ... | @@ -10,6 +10,7 @@ describe("Components", () => { |
10 | 10 | let profileServiceMock: any; |
11 | 11 | let $state: any; |
12 | 12 | let sweetAlert: any; |
13 | + let profile = { id: 1 }; | |
13 | 14 | |
14 | 15 | beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { |
15 | 16 | $rootScope = _$rootScope_; |
... | ... | @@ -23,10 +24,10 @@ describe("Components", () => { |
23 | 24 | articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["create"]); |
24 | 25 | |
25 | 26 | let getCurrentProfileResponse = $q.defer(); |
26 | - getCurrentProfileResponse.resolve({ id: 1 }); | |
27 | + getCurrentProfileResponse.resolve(profile); | |
27 | 28 | |
28 | 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 | 32 | profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise); |
32 | 33 | articleServiceMock.create = jasmine.createSpy("create").and.returnValue(articleCreate.promise); |
... | ... | @@ -37,7 +38,7 @@ describe("Components", () => { |
37 | 38 | component.save(); |
38 | 39 | $rootScope.$apply(); |
39 | 40 | expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled(); |
40 | - expect(articleServiceMock.create).toHaveBeenCalledWith(1, component.article); | |
41 | + expect(articleServiceMock.create).toHaveBeenCalledWith(component.article, profile); | |
41 | 42 | done(); |
42 | 43 | }); |
43 | 44 | ... | ... |
src/app/cms/cms.component.ts
... | ... | @@ -24,6 +24,7 @@ export class Cms { |
24 | 24 | this.profileService.getCurrentProfile().then((profile: Profile) => { |
25 | 25 | return this.articleService.create(this.article, <any>profile); |
26 | 26 | }).then((result: noosfero.RestResult<noosfero.Article>) => { |
27 | + console.log('RESULT', result); | |
27 | 28 | let resultData: noosfero.Article = <noosfero.Article>result.data; |
28 | 29 | this.$state.transitionTo('main.profile.page', { page: resultData.path, profile: resultData.profile.identifier }); |
29 | 30 | this.SweetAlert.swal({ | ... | ... |
src/app/components/noosfero-articles/blog/blog.component.spec.ts
... | ... | @@ -101,11 +101,11 @@ describe("Blog Component", () => { |
101 | 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 | 106 | // defining a mock result to articleService.getChildren method |
107 | 107 | articleService.getChildren = (article_id: number, filters: {}) => { |
108 | - return promiseResultTemplate(articles); | |
108 | + return promiseResultTemplate(result); | |
109 | 109 | }; |
110 | 110 | |
111 | 111 | createComponentFromClass(BlogContainerComponent).then((fixture) => { | ... | ... |
src/app/components/noosfero-articles/blog/blog.component.ts
... | ... | @@ -34,7 +34,7 @@ export class ArticleBlog { |
34 | 34 | this.articleService |
35 | 35 | .getChildren(this.article, filters) |
36 | 36 | .then((result: noosfero.RestResult<noosfero.Article>) => { |
37 | - this.totalPosts = <number>(<any>result.data)["_headers"]["total"]; | |
37 | + this.totalPosts = <number>result.headers("total"); | |
38 | 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("Components", () => { |
18 | 18 | new Provider('ArticleService', { |
19 | 19 | useValue: { |
20 | 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 | 1 | import { Injectable, Inject } from "ng-forward"; |
2 | 2 | import {RestangularService} from "./restangular_service"; |
3 | +import {ProfileService} from "./profile.service"; | |
4 | + | |
3 | 5 | @Injectable() |
4 | -@Inject("Restangular", "$q") | |
6 | +@Inject("Restangular", "$q", "$log", ProfileService) | |
5 | 7 | |
6 | 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 | 11 | super(Restangular, $q, $log); |
10 | 12 | } |
11 | 13 | |
... | ... | @@ -57,7 +59,8 @@ export class ArticleService extends RestangularService<noosfero.Article> { |
57 | 59 | // TODO -> change all Restangular services to this approach "Return promise to a specific type" |
58 | 60 | // it makes easy consume the service |
59 | 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 | 66 | getChildren<T>(article: noosfero.Article, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article>> { | ... | ... |