-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9716e05
commit 079441f
Showing
4 changed files
with
61 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,59 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { TestBed } from '@angular/core/testing' | ||
import { HttpRequest } from '@angular/common/http' | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing' | ||
|
||
import { HttpClientTestingModule } from '@angular/common/http/testing' | ||
|
||
import { XmlrpcService } from './xmlrpc.service'; | ||
import { XmlrpcService } from './xmlrpc.service' | ||
|
||
describe('XmlrpcService', () => { | ||
let service: XmlrpcService; | ||
let service: XmlrpcService | ||
let httpTestingController: HttpTestingController | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
HttpClientTestingModule | ||
] | ||
}); | ||
service = TestBed.inject(XmlrpcService); | ||
}); | ||
imports: [HttpClientTestingModule], | ||
providers: [XmlrpcService] | ||
}) | ||
service = TestBed.inject(XmlrpcService) | ||
httpTestingController = TestBed.inject(HttpTestingController) | ||
}) | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); | ||
expect(service).toBeTruthy() | ||
}) | ||
|
||
it('should parse XML-RPC response', () => { | ||
const mockResponse = | ||
"<?xml version='1.0'?><methodResponse><params><param><value><int>5</int></value></param></params></methodResponse>" | ||
expect(service.parseResponse(mockResponse)).toEqual(5) | ||
}) | ||
|
||
it('should return param*param', () => { | ||
const param = Math.floor(Math.random() * Math.floor(10)) + 2 | ||
console.log("PARAM", param) | ||
const url = 'http://mockaddress' | ||
|
||
const mockResponse = | ||
"<?xml version=\"1.0\"?><methodResponse><params><param><value><int>" + | ||
(param * param) + | ||
"</int></value></param></params></methodResponse>" | ||
|
||
service.callMethod(url, 'square', [param]).subscribe( | ||
data => { | ||
console.log("RESPONSE", data) | ||
expect(service.parseResponse(data)).toEqual(param*param) | ||
} | ||
) | ||
|
||
const req = httpTestingController.expectOne((hr: HttpRequest<any>) => { | ||
expect(hr.url).toBe(url) | ||
expect(hr.method).toBe('POST') | ||
expect(service.parseResponse(hr.body)).toEqual(param) | ||
return true | ||
}) | ||
|
||
req.flush(mockResponse) | ||
|
||
httpTestingController.verify() | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters