From 5518709db727d0f86ec6dc3f8245674a5767e735 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 24 Mar 2016 18:17:19 -0300 Subject: [PATCH] Add the community service to api --- src/lib/ng-noosfero-api/http/community.service.spec.ts | 33 +++++++++++++++++++++++++++++++++ src/lib/ng-noosfero-api/http/community.service.ts | 23 +++++++++++++++++++++++ src/lib/ng-noosfero-api/interfaces/community.ts | 11 +++++++++++ 3 files changed, 67 insertions(+), 0 deletions(-) create mode 100644 src/lib/ng-noosfero-api/http/community.service.spec.ts create mode 100644 src/lib/ng-noosfero-api/http/community.service.ts create mode 100644 src/lib/ng-noosfero-api/interfaces/community.ts diff --git a/src/lib/ng-noosfero-api/http/community.service.spec.ts b/src/lib/ng-noosfero-api/http/community.service.spec.ts new file mode 100644 index 0000000..6406ce5 --- /dev/null +++ b/src/lib/ng-noosfero-api/http/community.service.spec.ts @@ -0,0 +1,33 @@ +import {CommunityService} from "./community.service"; + + +describe("Services", () => { + + describe("Community Service", () => { + + let $httpBackend: ng.IHttpBackendService; + let communityService: CommunityService; + + beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => { + $translateProvider.translations('en', {}); + })); + + beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _CommunityService_: CommunityService) => { + $httpBackend = _$httpBackend_; + communityService = _CommunityService_; + })); + + describe("Succesfull requests", () => { + + it("should list communities", (done) => { + $httpBackend.expectGET(`/api/v1/communities`).respond(200, { communities: [{ name: "community1" }] }); + communityService.list().then((result: noosfero.RestResult) => { + expect(result.data).toEqual([{ name: "community1" }]); + done(); + }); + $httpBackend.flush(); + }); + }); + + }); +}); diff --git a/src/lib/ng-noosfero-api/http/community.service.ts b/src/lib/ng-noosfero-api/http/community.service.ts new file mode 100644 index 0000000..987adaa --- /dev/null +++ b/src/lib/ng-noosfero-api/http/community.service.ts @@ -0,0 +1,23 @@ +import { Injectable, Inject } from "ng-forward"; +import {RestangularService} from "./restangular_service"; + +@Injectable() +@Inject("Restangular", "$q", "$log") +export class CommunityService extends RestangularService { + + constructor(Restangular: restangular.IService, $q: ng.IQService, $log: ng.ILogService) { + super(Restangular, $q, $log); + } + + getResourcePath() { + return "communities"; + } + + getDataKeys() { + return { + singular: 'community', + plural: 'communities' + }; + } + +} diff --git a/src/lib/ng-noosfero-api/interfaces/community.ts b/src/lib/ng-noosfero-api/interfaces/community.ts new file mode 100644 index 0000000..3a37cf5 --- /dev/null +++ b/src/lib/ng-noosfero-api/interfaces/community.ts @@ -0,0 +1,11 @@ +namespace noosfero { + /** + * @ngdoc interface + * @name noosfero.Community + * @description + * A representation of a Community in Noosfero. + */ + export interface Community extends Profile { + + } +} -- libgit2 0.21.2