Commit 6da17d6e86e610e2939e29ffd67d6bff8ea5ca67
1 parent
3151a6e3
Exists in
master
and in
34 other branches
Added tests for profile service
Showing
2 changed files
with
76 additions
and
13 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,65 @@ |
| 1 | +import {Profile} from "../../../app/models/interfaces"; | |
| 2 | +import {ProfileService} from "./profile.service"; | |
| 3 | + | |
| 4 | + | |
| 5 | +describe("Services", () => { | |
| 6 | + | |
| 7 | + describe("Profile Service", () => { | |
| 8 | + | |
| 9 | + let $httpBackend: ng.IHttpBackendService; | |
| 10 | + let profileService: ProfileService; | |
| 11 | + | |
| 12 | + beforeEach(angular.mock.module("noosferoApp")); | |
| 13 | + | |
| 14 | + beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _ProfileService_: ProfileService) => { | |
| 15 | + $httpBackend = _$httpBackend_; | |
| 16 | + profileService = _ProfileService_; | |
| 17 | + })); | |
| 18 | + | |
| 19 | + | |
| 20 | + describe("Succesfull requests", () => { | |
| 21 | + | |
| 22 | + it("should return profile by its identifier", (done) => { | |
| 23 | + let identifier = 'profile1'; | |
| 24 | + $httpBackend.expectGET(`/api/v1/profiles?identifier=${identifier}`).respond(200, [{ name: "profile1" }]); | |
| 25 | + profileService.getByIdentifier(identifier).then((response: restangular.IResponse) => { | |
| 26 | + expect(response.data[0]).toEqual({ name: "profile1" }); | |
| 27 | + done(); | |
| 28 | + }); | |
| 29 | + $httpBackend.flush(); | |
| 30 | + }); | |
| 31 | + | |
| 32 | + it("should return the members of a profile", (done) => { | |
| 33 | + let profileId = 1; | |
| 34 | + $httpBackend.expectGET(`/api/v1/profiles/${profileId}/members`).respond(200, [{ name: "profile1" }]); | |
| 35 | + profileService.getProfileMembers(profileId).then((response: restangular.IResponse) => { | |
| 36 | + expect(response.data[0]).toEqual({ name: "profile1" }); | |
| 37 | + done(); | |
| 38 | + }); | |
| 39 | + $httpBackend.flush(); | |
| 40 | + }); | |
| 41 | + | |
| 42 | + it("should return the boxes of a profile", (done) => { | |
| 43 | + let profileId = 1; | |
| 44 | + $httpBackend.expectGET(`/api/v1/profiles/${profileId}/boxes`).respond(200, [{ position: 1 }]); | |
| 45 | + profileService.getBoxes(profileId).then((response: restangular.IResponse) => { | |
| 46 | + expect(response.data[0]).toEqual({ position: 1 }); | |
| 47 | + done(); | |
| 48 | + }); | |
| 49 | + $httpBackend.flush(); | |
| 50 | + }); | |
| 51 | + | |
| 52 | + it("should return activities of a profile", (done) => { | |
| 53 | + let profileId = 1; | |
| 54 | + $httpBackend.expectGET(`/api/v1/profiles/${profileId}/activities`).respond(200, [{ verb: "create_article" }]); | |
| 55 | + profileService.getActivities(profileId).then((response: restangular.IResponse) => { | |
| 56 | + expect(response.data[0]).toEqual({ verb: "create_article" }); | |
| 57 | + done(); | |
| 58 | + }); | |
| 59 | + $httpBackend.flush(); | |
| 60 | + }); | |
| 61 | + }); | |
| 62 | + | |
| 63 | + | |
| 64 | + }); | |
| 65 | +}); | ... | ... |
src/lib/ng-noosfero-api/http/profile.service.ts
| ... | ... | @@ -4,28 +4,26 @@ import { Injectable, Inject } from "ng-forward"; |
| 4 | 4 | @Inject("Restangular") |
| 5 | 5 | export class ProfileService { |
| 6 | 6 | |
| 7 | - constructor(private Restangular: any) { | |
| 7 | + constructor(private Restangular: any) { } | |
| 8 | 8 | |
| 9 | + getByIdentifier(identifier: string) { | |
| 10 | + return this.Restangular.one('profiles').get({ identifier: identifier }); | |
| 9 | 11 | } |
| 10 | 12 | |
| 11 | - getActivities(profileId: number, options: any = {}) { | |
| 12 | - return this.get(profileId).customGET("activities", options); | |
| 13 | - } | |
| 14 | - | |
| 15 | - get(profileId: number) { | |
| 16 | - return this.Restangular.one('profiles', profileId); | |
| 13 | + getProfileMembers(profileId: number, params?: any) { | |
| 14 | + return this.get(profileId).customGET("members", params); | |
| 17 | 15 | } |
| 18 | 16 | |
| 19 | - getProfileMembers(profileId: number, filters: any) { | |
| 20 | - return this.get(profileId).customGET("members", filters); | |
| 17 | + getBoxes(profileId: number) { | |
| 18 | + return this.get(profileId).customGET('boxes'); | |
| 21 | 19 | } |
| 22 | 20 | |
| 23 | - getByIdentifier(identifier: string) { | |
| 24 | - return this.Restangular.one('profiles').get({ identifier: identifier }); | |
| 21 | + getActivities(profileId: number, params?: any) { | |
| 22 | + return this.get(profileId).customGET("activities", params); | |
| 25 | 23 | } |
| 26 | 24 | |
| 27 | - getBoxes(profileId: number) { | |
| 28 | - return this.get(profileId).customGET('boxes'); | |
| 25 | + private get(profileId: number) { | |
| 26 | + return this.Restangular.one('profiles', profileId); | |
| 29 | 27 | } |
| 30 | 28 | |
| 31 | 29 | } | ... | ... |