Commit ba3482c30cca9c17203579b778932dcefec0d6e4
1 parent
f89615d5
Add test for block service
Showing
1 changed file
with
36 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,36 @@ |
| 1 | +import {BlockService} from "./block.service"; | |
| 2 | + | |
| 3 | + | |
| 4 | +describe("Services", () => { | |
| 5 | + | |
| 6 | + describe("Block Service", () => { | |
| 7 | + | |
| 8 | + let $httpBackend: ng.IHttpBackendService; | |
| 9 | + let blockService: BlockService; | |
| 10 | + | |
| 11 | + beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => { | |
| 12 | + $translateProvider.translations('en', {}); | |
| 13 | + })); | |
| 14 | + | |
| 15 | + beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _BlockService_: BlockService) => { | |
| 16 | + $httpBackend = _$httpBackend_; | |
| 17 | + blockService = _BlockService_; | |
| 18 | + })); | |
| 19 | + | |
| 20 | + | |
| 21 | + describe("Succesfull requests", () => { | |
| 22 | + | |
| 23 | + it("should return api content of a block", (done) => { | |
| 24 | + let blockId = 1; | |
| 25 | + $httpBackend.expectGET(`/api/v1/blocks/${blockId}`).respond(200, { block: { api_content: [{ name: "article1" }] } }); | |
| 26 | + blockService.getApiContent(<noosfero.Block>{ id: blockId }).then((content: any) => { | |
| 27 | + expect(content).toEqual([{ name: "article1" }]); | |
| 28 | + done(); | |
| 29 | + }); | |
| 30 | + $httpBackend.flush(); | |
| 31 | + }); | |
| 32 | + }); | |
| 33 | + | |
| 34 | + | |
| 35 | + }); | |
| 36 | +}); | ... | ... |