From 9fe4faad431eae21219c6828ac1c2fefb6eb64dd Mon Sep 17 00:00:00 2001 From: leejinho Date: Mon, 20 Apr 2020 10:20:27 +0900 Subject: [PATCH] =?UTF-8?q?ng=20test=20=EA=B4=80=EB=A0=A8=20=EC=86=8C?= =?UTF-8?q?=EC=8A=A4=20=EC=88=98=EC=A0=95=EB=B3=B8.=20=EC=BB=B4=ED=8F=AC?= =?UTF-8?q?=EB=84=8C=ED=8A=B8=20=EA=B4=80=EB=A0=A8=EC=9D=80=20=EB=AF=B8?= =?UTF-8?q?=EC=99=84=EB=A3=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 21 ++- package.json | 4 + .../lib/services/common-api.service.spec.ts | 15 +- .../lib/services/external-api.service.spec.ts | 15 +- .../services/browser-native.service.spec.ts | 12 +- .../authentication-protocol.service.spec.ts | 136 +++++++++++++++++- .../src/lib/services/protocol.service.spec.ts | 60 +++++++- .../change-password.component.spec.ts | 74 +++++++++- .../lib/components/login.component.spec.ts | 70 ++++++++- 9 files changed, 389 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 11b7871..50c680b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2410,7 +2410,8 @@ }, "@ucap/ng-web-socket": { "version": "file:pack/ucap-ng-web-socket-0.0.2.tgz", - "integrity": "sha512-hMn8niCiRfR3ZUzE0oqspJGlGl0DKvLizkVMphF+JenqwARQcBYR+G7e+4HPEGyRbu0LtimkhMfExzJFTHky3A==" + "integrity": "sha512-hMn8niCiRfR3ZUzE0oqspJGlGl0DKvLizkVMphF+JenqwARQcBYR+G7e+4HPEGyRbu0LtimkhMfExzJFTHky3A==", + "dev": true }, "@ucap/ng-web-storage": { "version": "file:pack/ucap-ng-web-storage-0.0.3.tgz", @@ -2423,6 +2424,12 @@ "integrity": "sha512-nWev387pHxeBHtOu0EvRTVQ0/JeJL44Ew0PzQaiqHsC5mghkJ6ok7z22nk9nmuZ7lONxGJmW7CHT8X8lyviZJg==", "dev": true }, + "@ucap/protocol": { + "version": "0.0.11", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@ucap/protocol/-/protocol-0.0.11.tgz", + "integrity": "sha512-nmwejglPVtC7elUn8x05ENFyqFz0z2pFibpblqAUW3m8HQHBSIKLqfctVsHzk5iP9/JyCDCTDuJ2DjMhMVJB8g==", + "dev": true + }, "@ucap/protocol-authentication": { "version": "0.0.5", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/@ucap/protocol-authentication/-/protocol-authentication-0.0.5.tgz", @@ -4945,6 +4952,12 @@ "randomfill": "^1.0.3" } }, + "crypto-js": { + "version": "4.0.0", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/crypto-js/-/crypto-js-4.0.0.tgz", + "integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg==", + "optional": true + }, "crypto-random-string": { "version": "2.0.0", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/crypto-random-string/-/crypto-random-string-2.0.0.tgz", @@ -11516,6 +11529,12 @@ "integrity": "sha512-w7fLxIRCRT7U8Qu53jQnJyPkYZIaR4n5151KMfcJlO/A9397Wxb1amJvROTK6TOnp7PfoAmg/qXiNHI+08jRfA==", "dev": true }, + "queueing-subject": { + "version": "0.3.4", + "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/queueing-subject/-/queueing-subject-0.3.4.tgz", + "integrity": "sha512-sdpymi9eq80oZyg74NrIGr1GHKIDRmBLZp+xqOct8Do5KpKalPsSz9NxApZb0S2j+EEDMzDlosBN5NJGFLmS7A==", + "optional": true + }, "quick-lru": { "version": "1.1.0", "resolved": "http://10.81.13.221:8081/nexus/repository/npm-all/quick-lru/-/quick-lru-1.1.0.tgz", diff --git a/package.json b/package.json index ddd1ba4..a7202e8 100644 --- a/package.json +++ b/package.json @@ -225,5 +225,9 @@ "typescript": "~3.7.5", "webpack-bundle-analyzer": "^3.6.1", "zone.js": "~0.10.2" + }, + "optionalDependencies": { + "queueing-subject": "^0.3.4", + "crypto-js": "^4.0.0" } } diff --git a/projects/api-common/src/lib/services/common-api.service.spec.ts b/projects/api-common/src/lib/services/common-api.service.spec.ts index fd84d71..c4c0fb6 100644 --- a/projects/api-common/src/lib/services/common-api.service.spec.ts +++ b/projects/api-common/src/lib/services/common-api.service.spec.ts @@ -1,12 +1,23 @@ import { TestBed } from '@angular/core/testing'; import { CommonApiService } from './common-api.service'; +import { AXIOS_INSTANCE } from '@ucap/ng-core'; +import { _MODULE_CONFIG } from '../config/token'; describe('CommonApiService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + let service: CommonApiService; + + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ + { provide: _MODULE_CONFIG, useValue: _MODULE_CONFIG }, + { provide: AXIOS_INSTANCE, useValue: AXIOS_INSTANCE } + ] + }); + service = TestBed.inject(CommonApiService); + }); it('should be created', () => { - const service: CommonApiService = TestBed.inject(CommonApiService); expect(service).toBeTruthy(); }); }); diff --git a/projects/api-external/src/lib/services/external-api.service.spec.ts b/projects/api-external/src/lib/services/external-api.service.spec.ts index 1634bb9..7aa4e99 100644 --- a/projects/api-external/src/lib/services/external-api.service.spec.ts +++ b/projects/api-external/src/lib/services/external-api.service.spec.ts @@ -1,12 +1,23 @@ import { TestBed } from '@angular/core/testing'; import { ExternalApiService } from './external-api.service'; +import { AXIOS_INSTANCE } from '@ucap/ng-core'; +import { _MODULE_CONFIG } from '../config/token'; describe('ExternalApiService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + let service: ExternalApiService; + + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ + { provide: _MODULE_CONFIG, useValue: _MODULE_CONFIG }, + { provide: AXIOS_INSTANCE, useValue: AXIOS_INSTANCE } + ] + }); + service = TestBed.inject(ExternalApiService); + }); it('should be created', () => { - const service: ExternalApiService = TestBed.inject(ExternalApiService); expect(service).toBeTruthy(); }); }); diff --git a/projects/native-browser/src/lib/services/browser-native.service.spec.ts b/projects/native-browser/src/lib/services/browser-native.service.spec.ts index 64a9b92..6b51a55 100644 --- a/projects/native-browser/src/lib/services/browser-native.service.spec.ts +++ b/projects/native-browser/src/lib/services/browser-native.service.spec.ts @@ -2,11 +2,19 @@ import { TestBed } from '@angular/core/testing'; import { BrowserNativeService } from './browser-native.service'; +import { AXIOS_INSTANCE } from '@ucap/ng-core'; + describe('BrowserNativeService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + let service: BrowserNativeService; + + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [{ provide: AXIOS_INSTANCE, useValue: AXIOS_INSTANCE }] + }); + service = TestBed.inject(BrowserNativeService); + }); it('should be created', () => { - const service: BrowserNativeService = TestBed.inject(BrowserNativeService); expect(service).toBeTruthy(); }); }); diff --git a/projects/protocol-authentication/src/lib/services/authentication-protocol.service.spec.ts b/projects/protocol-authentication/src/lib/services/authentication-protocol.service.spec.ts index 5201cda..cbbad06 100644 --- a/projects/protocol-authentication/src/lib/services/authentication-protocol.service.spec.ts +++ b/projects/protocol-authentication/src/lib/services/authentication-protocol.service.spec.ts @@ -1,14 +1,142 @@ import { TestBed } from '@angular/core/testing'; import { AuthenticationProtocolService } from './authentication-protocol.service'; +import { LogService } from '@ucap/ng-logger'; +import { ProtocolService } from '@ucap/ng-protocol'; +import { _MODULE_CONFIG } from '../config/token'; +import { of } from 'rxjs'; +import { + LoginRequest, + SSOMode, + SVC_TYPE_LOGIN, + SSVC_TYPE_LOGIN_REQ, + LogoutRequest, + SSVC_TYPE_LOGOUT_RES, + SSVC_TYPE_LOGIN_RES +} from '@ucap/protocol-authentication'; +import { DeviceType, LocaleCode } from '@ucap/core'; +import { ProtocolMessage } from '@ucap/protocol'; describe('AuthenticationProtocolService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + const senderSeq = '10045'; + let service: AuthenticationProtocolService; + let protocolServiceSpy: jasmine.SpyObj; + + beforeEach(() => { + const spyProtocolService = { + ...jasmine.createSpyObj('ProtocolService', ['connect', 'call']), + serverMessage$: of() + }; + + TestBed.configureTestingModule({ + providers: [ + AuthenticationProtocolService, + { provide: _MODULE_CONFIG, useValue: _MODULE_CONFIG }, + { provide: ProtocolService, useValue: spyProtocolService }, + { provide: LogService, useValue: LogService } + ] + }); + + service = TestBed.inject(AuthenticationProtocolService); + protocolServiceSpy = TestBed.inject(ProtocolService) as jasmine.SpyObj< + ProtocolService + >; + }); it('should be created', () => { - const service: AuthenticationProtocolService = TestBed.inject( - AuthenticationProtocolService - ); expect(service).toBeTruthy(); }); + + it('Test Login', (done) => { + protocolServiceSpy.call.and.returnValue( + of({ + serviceType: SVC_TYPE_LOGIN, + subServiceType: SSVC_TYPE_LOGIN_RES, + senderSeq, + bodyList: [ + 'test03', + '9826', + '9826테스트3https://dstalk.daesang.com/Extern/StreamProfileUrl.aspx?p_empno=ZZZZZZZ3사업부장하지마GUC10001090882377 01224646@daesang.com식자재사업부A330ZZZZZZZ3Test3Test3manager_enmanager_cn식자재사업부식자재사업부P ', + ' 2 0', + 'GUC100', + '205', + 'test03', + '1', + '', + 'N', + '0', + '1', + '회의중', + '테스트중', + 'GUC100', + '30', + '90', + 'Y', + '', + '', + '', + '0', + 'Y', + 'Y', + 'Y', + 'Y', + 'Y', + 'stubTokenString', + 'N', + '4', + '6', + ' ', + 'Y', + '2' + ] + }) + ); + + const req = { + loginId: '', + loginPw: '', + deviceType: DeviceType.PC, + deviceId: '', + token: '', + localeCode: LocaleCode.Korean, + pushId: '', + companyCode: '', + passwordEncodingType: 0, + clientVersion: '', + reconnect: false, + ip: '', + hostName: '', + ssoMode: SSOMode.NONE, + userSpecificInformation: '', + andId: '', + andPushRefreshYn: '' + } as LoginRequest; + // service.login(req)..returnValue(); + service.login(req).subscribe((res) => { + // console.log(res); + expect(res).toBeDefined(); + expect(res.companyCode).toBe('GUC100'); + expect(res.userInfo.seq).toBeDefined(); + done(); + }); + }); + + it('Test Logout', (done) => { + protocolServiceSpy.call.and.returnValue( + of({ + serviceType: SVC_TYPE_LOGIN, + subServiceType: SSVC_TYPE_LOGOUT_RES, + senderSeq, + bodyList: ['99'] + }) + ); + + const req = {} as LogoutRequest; + service.logout(req).subscribe((res) => { + // console.log(res); + expect(res).toBeDefined(); + expect(res.reasonCode).toBe(99); + done(); + }); + }); }); diff --git a/projects/protocol/src/lib/services/protocol.service.spec.ts b/projects/protocol/src/lib/services/protocol.service.spec.ts index 12129d3..ff95858 100644 --- a/projects/protocol/src/lib/services/protocol.service.spec.ts +++ b/projects/protocol/src/lib/services/protocol.service.spec.ts @@ -2,11 +2,67 @@ import { TestBed } from '@angular/core/testing'; import { ProtocolService } from './protocol.service'; +import { _MODULE_CONFIG } from '../config/token'; +import { WebSocketService } from '@ucap/ng-web-socket'; +import { LogService } from '@ucap/ng-logger'; +import { of } from 'rxjs'; +import { SVC_TYPE_PING, SSVC_TYPE_PING_REQ } from '@ucap/protocol-ping'; + +const MockModuleConfig = { + requestId: { + min: 0, + max: 0 + }, + timeout: { + expiredTime: 0, + checkInterval: 0 + } +}; + describe('ProtocolService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + let service: ProtocolService; + let logService: LogService; + let webSocketServiceSpy: jasmine.SpyObj; + + beforeEach(() => { + const spyWebSocketService = { + ...jasmine.createSpyObj('WebSocketService', ['connect']), + socketMessage$: of() + }; + + logService = new LogService({}); + + TestBed.configureTestingModule({ + providers: [ + ProtocolService, + { provide: _MODULE_CONFIG, useValue: MockModuleConfig }, + { provide: WebSocketService, useValue: spyWebSocketService }, + { provide: LogService, useValue: logService } + ] + }); + service = TestBed.inject(ProtocolService); + webSocketServiceSpy = TestBed.inject(WebSocketService) as jasmine.SpyObj< + WebSocketService + >; + }); it('should be created', () => { - const service: ProtocolService = TestBed.inject(ProtocolService); + expect(service).toBeTruthy(); + }); + + it('service connect', async () => { + await service.connect(); + expect(service).toBeTruthy(); + }); + + it('service send', () => { + try { + service.send(SVC_TYPE_PING, SSVC_TYPE_PING_REQ, ...[]); + logService.debug('s send'); + } catch (e) { + console.log(e); + } + expect(service).toBeTruthy(); }); }); diff --git a/projects/ui-authentication/src/lib/components/change-password.component.spec.ts b/projects/ui-authentication/src/lib/components/change-password.component.spec.ts index 8fcfab0..6d9343e 100644 --- a/projects/ui-authentication/src/lib/components/change-password.component.spec.ts +++ b/projects/ui-authentication/src/lib/components/change-password.component.spec.ts @@ -1,6 +1,23 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { ChangePasswordComponent } from './change-password.component'; +import { AuthenticationUiModule } from '../authentication-ui.module'; +import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; +import { ChangeDetectorRef } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { CommonModule } from '@angular/common'; +import { MatButtonModule } from '@angular/material/button'; +import { MatCheckboxModule } from '@angular/material/checkbox'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatIconModule } from '@angular/material/icon'; +import { MatInputModule } from '@angular/material/input'; +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; +import { MatSelectModule } from '@angular/material/select'; +import { I18nService, UCAP_I18N_NAMESPACE, I18nModule } from '@ucap/ng-i18n'; +import { LogService } from '@ucap/logger'; +import { FlexLayoutModule } from '@angular/flex-layout'; +import { UiModule } from '@ucap/ng-ui'; describe('Account::ChangePasswordComponent', () => { let component: ChangePasswordComponent; @@ -8,7 +25,33 @@ describe('Account::ChangePasswordComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ChangePasswordComponent] + imports: [ + BrowserModule, + BrowserAnimationsModule, + + CommonModule, + ReactiveFormsModule, + + FlexLayoutModule, + + MatButtonModule, + MatCheckboxModule, + MatFormFieldModule, + MatIconModule, + MatInputModule, + MatProgressSpinnerModule, + MatSelectModule + ], + declarations: [ + AuthenticationUiModule, + // { provide: FormBuilder, useValue: new FormBuilder() }, + // { provide: ChangeDetectorRef, useValue: ChangeDetectorRef }, + { provide: I18nService, useValue: new I18nService(new LogService({})) }, + { + provide: UCAP_I18N_NAMESPACE, + useValue: 'authentication' + } + ] }).compileComponents(); })); @@ -18,7 +61,30 @@ describe('Account::ChangePasswordComponent', () => { fixture.detectChanges(); }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + // it('should create', () => { + // // component.loginId = 'test03'; + // // component.phoneNumber = '01011112222'; + // // // component.encryptedLoginPw = 'encpw'; + // // fixture.detectChanges(); + + // // component.ngOnInit(); + + // expect(component).toBeTruthy(); + // }); + + // it('click changePassword', (done) => { + // component.loginId = 'test03'; + // component.phoneNumber = '01011112222'; + // // component.encryptedLoginPw = 'encpw'; + // fixture.detectChanges(); + + // component.ngOnInit(); + + // component.changePassword.subscribe((value) => { + // console.log(value); + // done(); + // }); + + // component.onClickChangePassword(); + // }); }); diff --git a/projects/ui-authentication/src/lib/components/login.component.spec.ts b/projects/ui-authentication/src/lib/components/login.component.spec.ts index 51f703f..a9ba1f3 100644 --- a/projects/ui-authentication/src/lib/components/login.component.spec.ts +++ b/projects/ui-authentication/src/lib/components/login.component.spec.ts @@ -1,6 +1,22 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { LoginComponent } from './login.component'; +import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; +import { CommonModule } from '@angular/common'; +import { ChangeDetectorRef } from '@angular/core'; +import { I18nService, UCAP_I18N_NAMESPACE } from '@ucap/ng-i18n'; +import { AuthenticationUiModule } from '../authentication-ui.module'; +import { MatSelectModule } from '@angular/material/select'; +import { Company } from '@ucap/api-external'; +import { LogService } from '@ucap/ng-logger'; +import { BrowserModule } from '@angular/platform-browser'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatButtonModule } from '@angular/material/button'; +import { MatCheckboxModule } from '@angular/material/checkbox'; +import { MatIconModule } from '@angular/material/icon'; +import { MatInputModule } from '@angular/material/input'; +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; describe('ui::authentication::LoginComponent', () => { let component: LoginComponent; @@ -8,7 +24,31 @@ describe('ui::authentication::LoginComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [LoginComponent] + imports: [ + BrowserModule, + BrowserAnimationsModule, + + CommonModule, + ReactiveFormsModule, + + MatButtonModule, + MatCheckboxModule, + MatFormFieldModule, + MatIconModule, + MatInputModule, + MatProgressSpinnerModule, + MatSelectModule + ], + providers: [ + AuthenticationUiModule, + // { provide: FormBuilder, useValue: new FormBuilder() }, + // { provide: ChangeDetectorRef, useValue: ChangeDetectorRef }, + { provide: I18nService, useValue: new I18nService(new LogService({})) }, + { + provide: UCAP_I18N_NAMESPACE, + useValue: 'authentication' + } + ] }).compileComponents(); })); @@ -19,6 +59,34 @@ describe('ui::authentication::LoginComponent', () => { }); it('should create', () => { + component.companyList = [ + { companyName: 'LG CNS', companyCode: 'GUC100' }, + { companyName: 'LG UCAP', companyCode: 'GUC101' } + ] as Company[]; + component.loginId = 'test'; + component.companyCode = 'GUC100'; + fixture.detectChanges(); + + component.ngOnInit(); + expect(component).toBeTruthy(); }); + + it('login', (done) => { + component.companyList = [ + { companyName: 'LG CNS', companyCode: 'GUC100' }, + { companyName: 'LG UCAP', companyCode: 'GUC101' } + ] as Company[]; + component.loginId = 'test'; + component.companyCode = 'GUC100'; + + component.ngOnInit(); + + component.login.subscribe((value) => { + console.log(value); + done(); + }); + + component.onClickLogin(); + }); });