From 44b513676fcaef0181725f0586419a3ecc552673 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Tue, 22 Mar 2016 14:35:29 -0300 Subject: [PATCH] Add tests to comment service --- src/lib/ng-noosfero-api/http/comment.service.spec.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+), 0 deletions(-) create mode 100644 src/lib/ng-noosfero-api/http/comment.service.spec.ts diff --git a/src/lib/ng-noosfero-api/http/comment.service.spec.ts b/src/lib/ng-noosfero-api/http/comment.service.spec.ts new file mode 100644 index 0000000..13dd8dd --- /dev/null +++ b/src/lib/ng-noosfero-api/http/comment.service.spec.ts @@ -0,0 +1,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`).respond(200, { comments: [{ name: "comment1" }] }); + commentService.getByArticle({id: articleId}).then((result: noosfero.RestResult) => { + 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 = { id: null}; + $httpBackend.expectPOST(`/api/v1/articles/${articleId}/comments`, comment ).respond(200, {comment: { id: 2 }}); + commentService.createInArticle({id: articleId}, comment).then((result: noosfero.RestResult) => { + expect(result.data).toEqual({ id: 2 }); + done(); + }); + $httpBackend.flush(); + }); + }); + + + }); +}); -- libgit2 0.21.2