From 88533c4c8bda07495d4221f0e2834c7c9bfb6cf8 Mon Sep 17 00:00:00 2001 From: Minsang Date: Tue, 30 Nov 2021 22:02:36 +0900 Subject: [PATCH] =?UTF-8?q?test:=20RequestFactory=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BBus/BBus.xcodeproj/project.pbxproj | 2 + .../RequestFactoryTests.swift | 55 +++++++++++++++---- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/BBus/BBus.xcodeproj/project.pbxproj b/BBus/BBus.xcodeproj/project.pbxproj index 18b31800..4e90b8fe 100644 --- a/BBus/BBus.xcodeproj/project.pbxproj +++ b/BBus/BBus.xcodeproj/project.pbxproj @@ -147,6 +147,7 @@ 87038A90273C11630078EAE3 /* GetStationsByRouteListFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87038A8F273C11630078EAE3 /* GetStationsByRouteListFetcher.swift */; }; 87038A92273C12320078EAE3 /* GetBusPosByRtidFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87038A91273C12320078EAE3 /* GetBusPosByRtidFetcher.swift */; }; 87038A94273C12E20078EAE3 /* GetStationByUidItemFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87038A93273C12E20078EAE3 /* GetStationByUidItemFetcher.swift */; }; + 87115EFA27564D0F00601770 /* RequestFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A5182A527550988001EA530 /* RequestFactory.swift */; }; 87285F5527461DB300CA3BA9 /* UINavigationControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87285F5427461DB300CA3BA9 /* UINavigationControllerExtension.swift */; }; 873578832732545D00CC8ECC /* CustomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873578822732545D00CC8ECC /* CustomNavigationBar.swift */; }; 87359B8D27311BF100F461A7 /* BusTagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87359B8C27311BF100F461A7 /* BusTagView.swift */; }; @@ -1636,6 +1637,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 87115EFA27564D0F00601770 /* RequestFactory.swift in Sources */, 4AF1E08F2756264600DE51C8 /* RequestFactoryTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/BBus/RequestFactoryTests/RequestFactoryTests.swift b/BBus/RequestFactoryTests/RequestFactoryTests.swift index 2f522e5a..927949ed 100644 --- a/BBus/RequestFactoryTests/RequestFactoryTests.swift +++ b/BBus/RequestFactoryTests/RequestFactoryTests.swift @@ -9,24 +9,59 @@ import XCTest class RequestFactoryTests: XCTestCase { + private var requestFactory: Requestable? + override func setUpWithError() throws { - // Put setup code here. This method is called before the invocation of each test method in the class. + super.setUp() + self.requestFactory = RequestFactory() } override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + self.requestFactory = nil } - func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. + func test_request_파라미터2개_생성_일치() throws { + // given + let mockUrl = "http://ws.bus.go.kr/testUrl" + let mockAccessKey = "uAtMsUVNMLIM%2FM9%3D%3D" + let mockParam = ["stId": "10001", "busRouteId": "1001001"] + let answer1 = URL(string: "http://ws.bus.go.kr/testUrl?stId=10001&busRouteId=1001001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D") + let answer2 = URL(string: "http://ws.bus.go.kr/testUrl?busRouteId=1001001&stId=10001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D") + let answers = [answer1, answer2] + + // when + guard let requestResult = self.requestFactory?.request(url: mockUrl, accessKey: mockAccessKey, params: mockParam) else { + XCTFail("request result is nil") + return + } + + // then + XCTAssertNotNil(requestResult) + XCTAssertTrue(answers.contains(requestResult.url)) } - func testPerformanceExample() throws { - // This is an example of a performance test case. - measure { - // Put the code you want to measure the time of here. + func test_request_파라미터3개_생성_일치() throws { + //given + let mockUrl = "http://www.BBus.test" + let mockAccessKey = "uAtMsUVNMLIM%2FM9%3D%3D" + let mockParam = ["stId": "10001", "routeId": "1001001", "ord": "1"] + let answer1 = URL(string: "http://www.BBus.test?stId=10001&routeId=1001001&ord=1&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D") + let answer2 = URL(string: "http://www.BBus.test?routeId=1001001&stId=10001&ord=1&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D") + let answer3 = URL(string: "http://www.BBus.test?ord=1&routeId=1001001&stId=10001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D") + let answer4 = URL(string: "http://www.BBus.test?stId=10001&ord=1&routeId=1001001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D") + let answer5 = URL(string: "http://www.BBus.test?routeId=1001001&ord=1&stId=10001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D") + let answer6 = URL(string: "http://www.BBus.test?ord=1&stId=10001&routeId=1001001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D") + let answers = [answer1, answer2, answer3, answer4, answer5, answer6] + + // when + guard let requestResult = self.requestFactory?.request(url: mockUrl, accessKey: mockAccessKey, params: mockParam) else { + XCTFail("request result is nil") + return } + + // then + XCTAssertNotNil(requestResult) + XCTAssertTrue(answers.contains(requestResult.url)) } - }