comment.service.spec.ts
1.83 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
import {CommentService} from "./comment.service";
describe("Services", () => {
describe("Comment Service", () => {
let $httpBackend: ng.IHttpBackendService;
let commentService: CommentService;
beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => {
$translateProvider.translations('en', {});
}));
beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _CommentService_: CommentService) => {
$httpBackend = _$httpBackend_;
commentService = _CommentService_;
}));
describe("Succesfull requests", () => {
it("should return comments by article", (done) => {
let articleId = 1;
$httpBackend.expectGET(`/api/v1/articles/${articleId}/comments?without_reply=true`).respond(200, { comments: [{ name: "comment1" }] });
commentService.getByArticle(<noosfero.Article>{ id: articleId }).then((result: noosfero.RestResult<noosfero.Comment[]>) => {
expect(result.data).toEqual([{ name: "comment1" }]);
done();
});
$httpBackend.flush();
});
it("should create a comment in an article", (done) => {
let articleId = 1;
let comment: noosfero.Comment = <any>{ id: null };
$httpBackend.expectPOST(`/api/v1/articles/${articleId}/comments`, comment).respond(200, { comment: { id: 2 } });
commentService.createInArticle(<noosfero.Article>{ id: articleId }, comment).then((result: noosfero.RestResult<noosfero.Comment>) => {
expect(result.data).toEqual({ id: 2 });
done();
});
$httpBackend.flush();
});
});
});
});