Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 1 | /* |
| 2 | ============LICENSE_START========================================== |
| 3 | =================================================================== |
| 4 | Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. |
Arundathi Patil | b1f449e | 2018-07-24 16:53:55 +0530 | [diff] [blame] | 5 | |
| 6 | Copyright (C) 2018 IBM Intellectual Property. All rights reserved. |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 7 | =================================================================== |
| 8 | |
| 9 | Unless otherwise specified, all software contained herein is licensed |
| 10 | under the Apache License, Version 2.0 (the License); |
| 11 | you may not use this software except in compliance with the License. |
| 12 | You may obtain a copy of the License at |
| 13 | |
| 14 | http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | |
| 16 | Unless required by applicable law or agreed to in writing, software |
| 17 | distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | See the License for the specific language governing permissions and |
| 20 | limitations under the License. |
| 21 | |
| 22 | ECOMP is a trademark and service mark of AT&T Intellectual Property. |
| 23 | ============LICENSE_END============================================ |
| 24 | */ |
| 25 | |
| 26 | /* tslint:disable:no-unused-variable */ |
| 27 | import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; |
| 28 | import { NO_ERRORS_SCHEMA, Output } from '@angular/core'; |
| 29 | import { MyvnfsComponent } from './myvnfs.component'; |
| 30 | import { FormsModule } from '@angular/forms'; |
| 31 | import { NotificationService } from './../../shared/services/notification.service'; |
| 32 | import { ParamShareService } from './../../shared/services/paramShare.service'; |
| 33 | import { MappingEditorService } from './../../shared/services/mapping-editor.service'; |
| 34 | import { DialogService } from 'ng2-bootstrap-modal'; |
| 35 | import { RouterTestingModule } from '@angular/router/testing'; |
| 36 | import { HttpUtilService } from '.././../shared/services/httpUtil/http-util.service'; |
| 37 | import { UtilityService } from '.././../shared/services/utilityService/utility.service'; |
| 38 | // import{TableFilterPipe} from '.././../shared/modules/tidy-table/table-filter.pipe'; |
| 39 | import { TidyTableModule } from '../../shared/modules/tidy-table/tidy-table.module'; |
| 40 | import { NgModule } from '@angular/core'; |
| 41 | import { NgProgress } from 'ngx-progressbar'; |
Arundathi Patil | b1f449e | 2018-07-24 16:53:55 +0530 | [diff] [blame] | 42 | import { NotificationsService } from 'angular2-notifications'; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 43 | |
| 44 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; |
| 45 | import { |
| 46 | HttpModule, |
| 47 | Http, |
| 48 | Response, |
| 49 | ResponseOptions, |
| 50 | XHRBackend |
| 51 | } from '@angular/http'; |
| 52 | |
| 53 | import { MockBackend } from '@angular/http/testing'; |
| 54 | describe('MyvnfsComponent', () => { |
| 55 | let component: MyvnfsComponent; |
| 56 | let fixture: ComponentFixture<MyvnfsComponent>; |
| 57 | |
| 58 | beforeEach(async(() => { |
| 59 | TestBed.configureTestingModule({ |
| 60 | declarations: [MyvnfsComponent], |
| 61 | schemas: [NO_ERRORS_SCHEMA], |
| 62 | imports: [FormsModule, RouterTestingModule, TidyTableModule, HttpModule, NgbModule.forRoot()], |
| 63 | providers: [ |
| 64 | |
| 65 | { provide: XHRBackend, useClass: MockBackend }, |
Arundathi Patil | b1f449e | 2018-07-24 16:53:55 +0530 | [diff] [blame] | 66 | NgProgress, UtilityService, ParamShareService, DialogService, NotificationService, HttpUtilService, MappingEditorService, NotificationsService] |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 67 | |
| 68 | }) |
| 69 | .compileComponents(); |
| 70 | })); |
| 71 | |
| 72 | beforeEach(() => { |
| 73 | |
| 74 | fixture = TestBed.createComponent(MyvnfsComponent); |
| 75 | component = fixture.componentInstance; |
| 76 | fixture.detectChanges(); |
| 77 | }); |
| 78 | |
| 79 | it('should create myvnfscomponent', () => { |
| 80 | expect(component).toBeTruthy(); |
| 81 | }); |
| 82 | it('Post call to get artifact', inject([HttpUtilService, XHRBackend], (httpUtilService, mockBackend) => { |
| 83 | |
| 84 | const mockResponse = { |
| 85 | "output": { |
| 86 | "data": { |
| 87 | "block": "{\"userID\":\"ug0221\",\"designInfo\":[{\"vnf-type\":\"demo123\",\"vnfc-type\":\"null\",\"protocol\":\"\",\"incart\":\"N\",\"action\":\"AllAction\",\"artifact-name\":\"reference_AllAction_demo123_0.0.1V.json\",\"artifact-type\":\"APPC-CONFIG\"}],\"statusInfo\":null,\"artifactInfo\":null}", |
| 88 | "status":{ |
| 89 | "code": "400", |
| 90 | "message": "success" |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | //"{'userID':'ug0221','designInfo':[{'vnf-type':'demo123','vnfc-type':'null','protocol':'','incart':'N','action':'AllAction','artifact-name':'reference_AllAction_demo123_0.0.1V.json','artifact-type':'APPC-CONFIG'}]}" |
| 97 | const data = { |
| 98 | 'input': { |
| 99 | 'design-request': { |
| 100 | 'request-id': "apiToken", |
| 101 | 'action': 'getDesigns', |
| 102 | 'payload': '{"userID": "","filter":"reference"}' |
| 103 | } |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | |
| 108 | mockBackend.connections.subscribe((connection) => { |
| 109 | connection.mockRespond(new Response(new ResponseOptions({ |
| 110 | body: JSON.stringify(mockResponse) |
| 111 | }))); |
| 112 | }); |
| 113 | component.getArtifacts(data) |
| 114 | httpUtilService.post({ |
| 115 | url: "test url", |
| 116 | data: data |
| 117 | }).subscribe((resp) => { |
| 118 | console.log("resp") |
| 119 | console.log(resp) |
| 120 | let block = JSON.parse(resp.output.data.block) |
| 121 | expect(block.userID).toBe("ug0221"); |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | }); |
| 127 | |
| 128 | |
| 129 | })) |
| 130 | it('Checking for the successfull post call', inject([HttpUtilService, XHRBackend], (httpUtilService, mockBackend) => { |
| 131 | |
| 132 | const mockResponse = { |
| 133 | "output": { |
| 134 | "data": { |
| 135 | "block": "{\"userID\":\"ug0221\",\"designInfo\":[{\"vnf-type\":\"demo123\",\"vnfc-type\":\"null\",\"protocol\":\"\",\"incart\":\"N\",\"action\":\"AllAction\",\"artifact-name\":\"reference_AllAction_demo123_0.0.1V.json\",\"artifact-type\":\"APPC-CONFIG\"}],\"statusInfo\":null,\"artifactInfo\":null}", |
| 136 | "status":{ |
| 137 | "code": "400", |
| 138 | "message": "success" |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | const data = { |
| 144 | 'input': { |
| 145 | 'design-request': { |
| 146 | 'request-id': "apiToken", |
| 147 | 'action': 'getDesigns', |
| 148 | 'payload': '{"userID": "","filter":"reference"}' |
| 149 | } |
| 150 | } |
| 151 | }; |
| 152 | |
| 153 | |
| 154 | mockBackend.connections.subscribe((connection) => { |
| 155 | connection.mockRespond(new Response(new ResponseOptions({ |
| 156 | body: JSON.stringify(mockResponse) |
| 157 | }))); |
| 158 | }); |
| 159 | component.getArtifacts(data) |
| 160 | httpUtilService.post({ |
| 161 | url: "test url", |
| 162 | data: data |
| 163 | }).subscribe((resp) => { |
| 164 | console.log("resp") |
| 165 | console.log(resp) |
| 166 | let block = JSON.parse(resp.output.data.status.code) |
| 167 | console.log("code",block) |
| 168 | expect(block).toBe(400); |
| 169 | }); |
Arundathi Patil | dfacced | 2018-07-31 14:34:39 +0530 | [diff] [blame^] | 170 | })); |
| 171 | |
| 172 | it('should test navigateToReference', ()=>{ |
| 173 | component.navigateToReference({paramData : 'data'}); |
| 174 | expect(JSON.parse(sessionStorage.getItem('updateParams'))).toEqual({paramData : 'data'}); |
| 175 | }); |
Arundathi Patil | b1f449e | 2018-07-24 16:53:55 +0530 | [diff] [blame] | 176 | }); |