Commit 5518709db727d0f86ec6dc3f8245674a5767e735

Authored by Victor Costa
1 parent 12de4066
Exists in master and in 1 other branch dev-fixes

Add the community service to api

src/lib/ng-noosfero-api/http/community.service.spec.ts 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +import {CommunityService} from "./community.service";
  2 +
  3 +
  4 +describe("Services", () => {
  5 +
  6 + describe("Community Service", () => {
  7 +
  8 + let $httpBackend: ng.IHttpBackendService;
  9 + let communityService: CommunityService;
  10 +
  11 + beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => {
  12 + $translateProvider.translations('en', {});
  13 + }));
  14 +
  15 + beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _CommunityService_: CommunityService) => {
  16 + $httpBackend = _$httpBackend_;
  17 + communityService = _CommunityService_;
  18 + }));
  19 +
  20 + describe("Succesfull requests", () => {
  21 +
  22 + it("should list communities", (done) => {
  23 + $httpBackend.expectGET(`/api/v1/communities`).respond(200, { communities: [{ name: "community1" }] });
  24 + communityService.list().then((result: noosfero.RestResult<noosfero.Community[]>) => {
  25 + expect(result.data).toEqual([{ name: "community1" }]);
  26 + done();
  27 + });
  28 + $httpBackend.flush();
  29 + });
  30 + });
  31 +
  32 + });
  33 +});
... ...
src/lib/ng-noosfero-api/http/community.service.ts 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +import { Injectable, Inject } from "ng-forward";
  2 +import {RestangularService} from "./restangular_service";
  3 +
  4 +@Injectable()
  5 +@Inject("Restangular", "$q", "$log")
  6 +export class CommunityService extends RestangularService<noosfero.Community> {
  7 +
  8 + constructor(Restangular: restangular.IService, $q: ng.IQService, $log: ng.ILogService) {
  9 + super(Restangular, $q, $log);
  10 + }
  11 +
  12 + getResourcePath() {
  13 + return "communities";
  14 + }
  15 +
  16 + getDataKeys() {
  17 + return {
  18 + singular: 'community',
  19 + plural: 'communities'
  20 + };
  21 + }
  22 +
  23 +}
... ...
src/lib/ng-noosfero-api/interfaces/community.ts 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +namespace noosfero {
  2 + /**
  3 + * @ngdoc interface
  4 + * @name noosfero.Community
  5 + * @description
  6 + * A representation of a Community in Noosfero.
  7 + */
  8 + export interface Community extends Profile {
  9 +
  10 + }
  11 +}
... ...