Created
August 25, 2021 20:48
-
-
Save somersbmatthews/d1ed23a848736a28aca2e791a345e527 to your computer and use it in GitHub Desktop.
actual problem
This file contains hidden or 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
// | |
// GIRC_Medical_Expert_AppTests.swift | |
// GIRC Medical Expert AppTests | |
// | |
// Created by Somers B Matthews on 8/19/21. | |
// | |
@testable import GIRC_Medical_Expert_App | |
import XCTest | |
import Firebase | |
import FirebaseAuth | |
class GIRC_Medical_Expert_AppTests: XCTestCase { | |
var testIdTokenValue: String = "" | |
let apiService = APIService() | |
override class func setUp() { | |
} | |
override func setUp() { | |
// super.setUp() | |
getToken() | |
} | |
func getToken() { | |
// var testIdTokenValue: String? | |
super.setUp() | |
Auth.auth().signInAnonymously { authResult, error in | |
print("Hello hello") | |
if error != nil { | |
print("this is error \(error)") | |
} | |
print("THIS IS user, \(String(describing: authResult?.user))") | |
guard let user = authResult?.user else { return } | |
let isAnonymous = user.isAnonymous // true | |
let uid = user.uid | |
print("THIS IS uid \(uid)") | |
} | |
let testUser = Auth.auth().currentUser | |
testUser?.getIDToken() { idToken, error in | |
if let error = error { | |
// Handle error | |
// XCTAssertNil(error, "firebase error: \(error.localizedDescription)") | |
print("Firebase idToken error") | |
return; | |
} | |
if let idToken = idToken { | |
// firebaseIdToken = idToken | |
self.testIdTokenValue = idToken | |
print("THIS IS FIREBASE ID TOKEN IN INTEGRATION TESTS") | |
print(self.testIdTokenValue) | |
XCTAssertNotNil(firebaseIdToken, "FIREBASE IDToken \(firebaseIdToken)") | |
return | |
} | |
} | |
// return testIdTokenValue! | |
} | |
func testRegisterMedicalExpert() { | |
print("test print succeeding") | |
print("this is testIdToken: \(self.testIdTokenValue)") | |
let apiService = APIService.shared | |
let expert = Expert(name: "Jim Bob", email: "[email protected]", expertise: "Otolaryngology", degree: "MD", deviceType: "Phone 6", FCMToken: "exampleToken1234") | |
// let token = refreshFirebaseIdToken() | |
// print("THIS IS TOKEN AFTER REFRESH IS CALLED \(token)") | |
apiService.makeAPIRequest(token: self.testIdTokenValue, method: "POST", route: "/v3/expert", body: expert) { (result: Result<GoodResponse, APIService.APIError >) in | |
switch result { | |
case .success(let response): | |
print(response.message ?? "cannot get message from response") | |
print("successfuly created medical expert") | |
// XCTAssertNot | |
case .failure(let apiError): | |
switch apiError { | |
case .error(let errorString): | |
print(errorString) | |
XCTAssertNil(errorString, "could not register User, api error: \(errorString)") | |
} | |
} | |
} | |
} | |
func testDeleteMedicalExpert() { | |
let apiService = APIService.shared | |
let emptyRequest = EmptyRequest() | |
apiService.makeAPIRequest(token: self.testIdTokenValue, method: "DELETE", route: "/v3/expert", body: emptyRequest) { (result: Result<GoodResponse, APIService.APIError >) in | |
switch result { | |
case .success(let response): | |
print(response.message ?? "cannot get message from response") | |
print("successfuly deleted medical expert") | |
case .failure(let apiError): | |
switch apiError { | |
case .error(let errorString): | |
print(errorString) | |
XCTFail() | |
} | |
} | |
} | |
} | |
func testCreateENTIncident() { | |
let apiService = APIService.shared | |
let swallowedObject1 = SwallowedObject(ID: "1234567890", incidentID: "12345678900", radioOpacity: "No", imaging: "Yes", anteriorPhoto: "photo1.jpg", posteriorPhoto: "photo2.jpg", lateralPhoto: "photo3.jpg", anteriorLongestLength: 34.2, posteriorLongestLength: 22.7, lateralLongestLength: 12.3, objectLocation: "Stomach", numberOfThisObject: "1", objectIntact: "Yes", numberOfPieces: "1", objectDescription: "this is the first fake data object", objectShape: "Sphere", objectCustomShape: "Square", objectDimensionality: "2D", otherCharacteristics: ["Pointed, Smooth"], material: "Paper", customMaterial: "Metal", isBatteryOrMagnet: "Neither", batteryType: "", customBatteryType: "", batteryImprintCode: "1a2345f", mitigatingFeatures: ["mitigating feature 1, mitigating feature 2"], customMitigatingFeatures: ["custom mitigating feature 1, custom mitigating feature 2"], negativePoleDirection: "negative", honey: "No", sucralfate: "No", aceticAcid: "No", magnetType: "fridge", customMagnetType: "", deviceType: "iPhone 6", submitted: true) | |
let swallowedObject2 = SwallowedObject(ID: "1234567790", incidentID: "12345678900", radioOpacity: "No", imaging: "Yes", anteriorPhoto: "photo3.jpg", posteriorPhoto: "photo3.jpg", lateralPhoto: "photo4.jpg", anteriorLongestLength: 22.3, posteriorLongestLength: 43.5, lateralLongestLength: 12.2, objectLocation: "throat", numberOfThisObject: "1", objectIntact: "Yes", numberOfPieces: "1", objectDescription: "This is second fake object", objectShape: "Sphere", objectCustomShape: "Square", objectDimensionality: "3D", otherCharacteristics: ["smooth","pointed"], material: "Wood", customMaterial: "Plastic", isBatteryOrMagnet: "Battery", batteryType: "Button Battery", customBatteryType: "", batteryImprintCode: "0iu8975", mitigatingFeatures: ["mitigating feature 1, mitigating feature 2"], customMitigatingFeatures: [""], negativePoleDirection: "Positive", honey: "No", sucralfate: "Yes", aceticAcid: "No", magnetType: "", customMagnetType: "", deviceType: "iPhone 6", submitted: false) | |
let swallowedObjects = [SwallowedObject](arrayLiteral: swallowedObject1, swallowedObject2) | |
let newENTIncident = ENTIncident(ID: "12345678900", country: "USA", year: "2017", ageYears: "0", ageMonths: "3" , gender: "Male", incidentDescription: "this is a fake ENT incident", daysUntilRemoval: 3, hoursUntilRemoval: 2, minutesUntilRemoval: 1, removalStrategy: "Forceps", removalSetting: "Operating Room", openSurgery: "No", easeOfRemoval: "difficult", wasIncidentLifeThreatening: "Yes", symptoms: ["coughing", "vomiting"], customSymptoms: [], symptomSeverity: "severe", complications: ["complication 1, complication 2"], customComplications: ["custom complication 1", "custom complication 2"], anesthesia: "anesthesia 1", prognosis: "Alive", hospitalStay: "2 weeks", deviceType: "iPhone 6", submitted: true, swallowedObjects: swallowedObjects) | |
apiService.makeAPIRequest(token: self.testIdTokenValue, method: "POST", route: "/v3/entincident", body: newENTIncident) { (result: Result<GoodResponse, APIService.APIError >) in | |
switch result { | |
case .success(let response): | |
print(response.message) | |
print("successfuly deleted medical expert") | |
case .failure(let apiError): | |
switch apiError { | |
case .error(let errorString): | |
print(errorString) | |
XCTFail() | |
} | |
} | |
} | |
} | |
func testDeleteENTIncidents() { | |
let apiService = APIService.shared | |
let emptyRequest = EmptyRequest() | |
apiService.makeAPIRequest(token: self.testIdTokenValue, method: "DELETE", route: "/v3/entincident", body: emptyRequest) { (result: Result<GoodResponse, APIService.APIError >) in | |
switch result { | |
case .success(let response): | |
print(response.message) | |
print("successfuly deleted ENT Incident") | |
case .failure(let apiError): | |
switch apiError { | |
case .error(let errorString): | |
print(errorString) | |
XCTFail() | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment