Commit 44b513676fcaef0181725f0586419a3ecc552673
1 parent
50c1b3c3
Exists in
master
and in
1 other branch
Add tests to comment service
Showing
1 changed file
with
47 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,47 @@ |
1 | +import {CommentService} from "./comment.service"; | |
2 | + | |
3 | + | |
4 | +describe("Services", () => { | |
5 | + | |
6 | + describe("Comment Service", () => { | |
7 | + | |
8 | + let $httpBackend: ng.IHttpBackendService; | |
9 | + let commentService: CommentService; | |
10 | + | |
11 | + beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => { | |
12 | + $translateProvider.translations('en', {}); | |
13 | + })); | |
14 | + | |
15 | + beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _CommentService_: CommentService) => { | |
16 | + $httpBackend = _$httpBackend_; | |
17 | + commentService = _CommentService_; | |
18 | + })); | |
19 | + | |
20 | + | |
21 | + describe("Succesfull requests", () => { | |
22 | + | |
23 | + it("should return comments by article", (done) => { | |
24 | + let articleId = 1; | |
25 | + $httpBackend.expectGET(`/api/v1/articles/${articleId}/comments`).respond(200, { comments: [{ name: "comment1" }] }); | |
26 | + commentService.getByArticle(<noosfero.Article>{id: articleId}).then((result: noosfero.RestResult<noosfero.Comment[]>) => { | |
27 | + expect(result.data).toEqual([{ name: "comment1" }]); | |
28 | + done(); | |
29 | + }); | |
30 | + $httpBackend.flush(); | |
31 | + }); | |
32 | + | |
33 | + it("should create a comment in an article", (done) => { | |
34 | + let articleId = 1; | |
35 | + let comment: noosfero.Comment = <any>{ id: null}; | |
36 | + $httpBackend.expectPOST(`/api/v1/articles/${articleId}/comments`, comment ).respond(200, {comment: { id: 2 }}); | |
37 | + commentService.createInArticle(<noosfero.Article>{id: articleId}, comment).then((result: noosfero.RestResult<noosfero.Comment>) => { | |
38 | + expect(result.data).toEqual({ id: 2 }); | |
39 | + done(); | |
40 | + }); | |
41 | + $httpBackend.flush(); | |
42 | + }); | |
43 | + }); | |
44 | + | |
45 | + | |
46 | + }); | |
47 | +}); | ... | ... |