From c7ab5d79a97f4d981194b988790d16a12518ec6b Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Tue, 11 Oct 2016 11:35:25 +0100 Subject: [PATCH] replace the getApiService with the apiService in the tagService --- .../components/tag-actions.component.spec.ts | 9 +++++--- .../src/components/tag-list.component.spec.ts | 1 - .../tag-node-list.component.spec.ts | 7 +++++- .../src/services/tag.service.spec.ts | 22 +++++++++---------- .../src/services/tag.service.ts | 17 +++++++------- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts index df46e40240..17d39f4a4a 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts @@ -52,7 +52,6 @@ describe('Test ng2-alfresco-tag Tag actions list', () => { beforeEach(() => { fixture = TestBed.createComponent(TagActionsComponent); - component = fixture.componentInstance; debug = fixture.debugElement; element = fixture.nativeElement; @@ -122,11 +121,15 @@ describe('Test ng2-alfresco-tag Tag actions list', () => { let deleteButton: any = element.querySelector('#tag_delete_0'); deleteButton.click(); - fixture.detectChanges(); - expect(jasmine.Ajax.requests.at(1).url) .toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags/0ee933fa-57fc-4587-8a77-b787e814f1d2'); expect(jasmine.Ajax.requests.at(1).method).toBe('DELETE'); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json' + }); + done(); }); diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts index aa6bf3a6dd..73a4df705b 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts @@ -69,7 +69,6 @@ describe('Test ng2-alfresco-tag Tag list All ECM', () => { beforeEach(() => { fixture = TestBed.createComponent(TagList); - component = fixture.componentInstance; debug = fixture.debugElement; element = fixture.nativeElement; diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts index 0cd1ce2654..f5e99f0efb 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts @@ -68,7 +68,6 @@ describe('Test ng2-alfresco-tag Tag relative node list', () => { beforeEach(() => { fixture = TestBed.createComponent(TagNodeList); - component = fixture.componentInstance; debug = fixture.debugElement; element = fixture.nativeElement; @@ -124,6 +123,12 @@ describe('Test ng2-alfresco-tag Tag relative node list', () => { expect(jasmine.Ajax.requests.mostRecent().url). toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags/0ee933fa-57fc-4587-8a77-b787e814f1d2'); expect(jasmine.Ajax.requests.mostRecent().method).toBe('DELETE'); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json' + }); + done(); }); diff --git a/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts b/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts index d7f4b9c8be..ce66cbdb6a 100644 --- a/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts +++ b/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts @@ -43,16 +43,16 @@ describe('Tag service', () => { service = injector.get(TagService); }); + beforeEach(() => { + jasmine.Ajax.install(); + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + describe('Content tests', () => { - beforeEach(() => { - jasmine.Ajax.install(); - }); - - afterEach(() => { - jasmine.Ajax.uninstall(); - }); - it('removeTag should perform a call against the server', (done) => { service.removeTag('fake-node-id', 'fake-tag').subscribe(() => { expect(jasmine.Ajax.requests.mostRecent().method).toBe('DELETE'); @@ -80,7 +80,7 @@ describe('Tag service', () => { }); it('getAllTheTags should perform a call against the server', (done) => { - service.getAllTheTags('fake-node-id', 'fake-tag').subscribe(() => { + service.getAllTheTags().subscribe(() => { expect(jasmine.Ajax.requests.mostRecent().method).toBe('GET'); expect(jasmine.Ajax.requests.mostRecent().url) .toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/tags'); @@ -93,7 +93,7 @@ describe('Tag service', () => { }); it('getTagsByNodeId should perform a call against the server', (done) => { - service.getTagsByNodeId('fake-node-id', 'fake-tag').subscribe(() => { + service.getTagsByNodeId('fake-node-id').subscribe(() => { expect(jasmine.Ajax.requests.mostRecent().method).toBe('GET'); expect(jasmine.Ajax.requests.mostRecent().url) .toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags'); @@ -106,7 +106,7 @@ describe('Tag service', () => { }); it('getTagsByNodeId catch errors call', (done) => { - service.getTagsByNodeId('fake-node-id', 'fake-tag').subscribe(() => { + service.getTagsByNodeId('fake-node-id').subscribe(() => { }, () => { done(); }); diff --git a/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts b/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts index 32efc0fdec..4e60ac6487 100644 --- a/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts +++ b/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts @@ -16,8 +16,9 @@ */ import { Injectable } from '@angular/core'; -import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { Observable } from 'rxjs/Rx'; +import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { AlfrescoApiService } from 'ng2-alfresco-core'; /** * @returns {TagService} . @@ -29,32 +30,32 @@ export class TagService { /** * Constructor - * @param authService + * @param apiService */ - constructor(public authService: AlfrescoAuthenticationService) { + constructor(private authService: AlfrescoAuthenticationService, private apiService: AlfrescoApiService) { } getTagsByNodeId(nodeId: string): any { - return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.getNodeTags(nodeId)) + return Observable.fromPromise(this.apiService.getInstance().core.tagsApi.getNodeTags(nodeId)) .catch(this.handleError); } getAllTheTags() { - return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.getTags()) + return Observable.fromPromise(this.apiService.getInstance().core.tagsApi.getTags()) .catch(this.handleError); } addTag(nodeId: string, tagName: string): any { - let alfrescoApi: any = this.authService.getAlfrescoApi(); + let alfrescoApi: any = this.apiService.getInstance(); let tagBody = new alfrescoApi.core.TagBody(); tagBody.tag = tagName; - return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.addTag(nodeId, tagBody)) + return Observable.fromPromise(this.apiService.getInstance().core.tagsApi.addTag(nodeId, tagBody)) .catch(this.handleError); } removeTag(nodeId: string, tag: string): any { - return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.removeTag(nodeId, tag)) + return Observable.fromPromise(this.apiService.getInstance().core.tagsApi.removeTag(nodeId, tag)) .catch(this.handleError); }