community.service.spec.ts
2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {CommunityService} from "./community.service";
describe("Services", () => {
describe("Community Service", () => {
let $httpBackend: ng.IHttpBackendService;
let communityService: CommunityService;
beforeEach(angular.mock.module("main", ($translateProvider: angular.translate.ITranslateProvider) => {
$translateProvider.translations('en', {});
}));
beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _CommunityService_: CommunityService) => {
$httpBackend = _$httpBackend_;
communityService = _CommunityService_;
}));
describe("Succesfull requests", () => {
it("should list environment communities", (done) => {
$httpBackend.expectGET(`/api/v1/communities`).respond(200, { communities: [{ name: "community1" }] });
communityService.getByEnvironment().then((result: noosfero.RestResult<noosfero.Community[]>) => {
expect(result.data).toEqual([{ name: "community1" }]);
done();
});
$httpBackend.flush();
});
it("should list person communities", (done) => {
$httpBackend.expectGET(`/api/v1/people/1/communities`).respond(200, { communities: [{ name: "community1" }] });
let person = <any>{ id: 1 };
communityService.getByPerson(person).then((result: noosfero.RestResult<noosfero.Community[]>) => {
expect(result.data).toEqual([{ name: "community1" }]);
done();
});
$httpBackend.flush();
});
it("should list owner communities when it is an environment", (done) => {
$httpBackend.expectGET(`/api/v1/communities`).respond(200, { communities: [{ name: "community1" }] });
let owner = <any>{ id: 1 };
communityService.getByOwner(owner).then((result: noosfero.RestResult<noosfero.Community[]>) => {
done();
});
$httpBackend.flush();
});
it("should list owner communities when it is an person", (done) => {
$httpBackend.expectGET(`/api/v1/people/1/communities`).respond(200, { communities: [{ name: "community1" }] });
let owner = <any>{ id: 1, type: "Person" };
communityService.getByOwner(owner).then((result: noosfero.RestResult<noosfero.Community[]>) => {
done();
});
$httpBackend.flush();
});
});
});
});