Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ProfilesTests.swift
- // GWA-appTests
- //
- // Created by Joseph Reusing on 2018-04-24.
- // Copyright © 2018 manulife. All rights reserved.
- //
- import XCTest
- @testable import GWA_app
- class ProfilesTests: XCTestCase {
- let user = User()
- let profiles = Profiles()
- override func setUp() {
- super.setUp()
- }
- override func tearDown() {
- // Put teardown code here. This method is called after the invocation of each test method in the class.
- super.tearDown()
- }
- func testExample() {
- // This is an example of a functional test case.
- // Use XCTAssert and related functions to verify your tests produce the correct results.
- }
- func testPerformanceExample() {
- // This is an example of a performance test case.
- self.measure {
- // Put the code you want to measure the time of here.
- }
- }
- // Tests loading all the profiles and loadMyProfile
- func testLoadProfiles() {
- let _ = Profile()
- let expect1 = expectation(description: "Data should load")
- let expect2 = expectation(description: "MyProfile should load")
- self.user.login(email: "joseph_reusing@manulife.com", password: "123456", completion: {
- (error) in
- if error == nil {
- self.profiles.load {
- expect1.fulfill()
- }
- self.profiles.loadMyProfile {
- XCTAssert(self.profiles.myProfile != nil, "My Profile did not load.")
- expect2.fulfill()
- }
- }
- })
- waitForExpectations(timeout: 2, handler: {
- (error) in
- if let error = error {
- XCTFail("waitForExpectationsWithTimeout errored: \(error)")
- }
- })
- }
- // Test updating profile
- func testUpdateProfile() {
- let expect = expectation(description: "Profile should update.")
- self.user.login(email: "joseph_reusing@manulife.com", password: "123456", completion: {
- (error) in
- if error == nil {
- self.profiles.loadMyProfile {
- XCTAssert(self.profiles.myProfile != nil, "My Profile did not load.")
- if let myProfile = self.profiles.myProfile {
- myProfile.firstName = nil
- myProfile.lastName = nil
- myProfile.email = nil
- myProfile.jobTitle = nil
- myProfile.businessUnit = nil
- myProfile.homeOffice = nil
- myProfile.interests = nil
- myProfile.linkedInURL = nil
- self.profiles.updateMyProfile(completion: {
- (error) in
- XCTAssert(error == nil, "Failed to update my profile.")
- myProfile.firstName = "Joseph"
- myProfile.lastName = "Reusing"
- myProfile.email = "joseph_reusing@manulife.com"
- myProfile.jobTitle = "Software Developer"
- myProfile.businessUnit = "Red Lab"
- myProfile.homeOffice = "151 Charles St."
- myProfile.interests = "Fun stuff"
- myProfile.linkedInURL = nil
- self.profiles.updateMyProfile(completion: {
- (error) in
- XCTAssert(error == nil, "Failed to update my profile.")
- expect.fulfill()
- })
- })
- }
- }
- }
- })
- waitForExpectations(timeout: 2, handler: {
- (error) in
- if let error = error {
- XCTFail("waitForExpectationsWithTimeout errored: \(error)")
- }
- })
- }
- // Test the functions unverified users will use
- func testUnverified() {
- let expect1 = expectation(description: "Should get pid from email.")
- let expect2 = expectation(description: "Should create unfound profile.")
- self.user.login(email: "joseph_reusing@manulife.com", password: "123456", completion: {
- (error) in
- if error == nil {
- self.profiles.getProfileByEmail(email: "unit_tester@manulife.com", completion: {
- pid in
- XCTAssert(pid == "-LAOKj6llCIP1TeU7yDK", "Incorrect PID of unit_tester@manulife.com")
- expect1.fulfill()
- })
- self.profiles.createUnfound(name: "Unfound Test", email: "unfound_test@manulife.com", completion: {
- (new_pid) in
- XCTAssert(new_pid != nil, "No PID created for unfound profile.")
- expect2.fulfill()
- })
- self.profiles.loadNameEmail(pid: "-LAOKj6llCIP1TeU7yDK", completion: {
- (name, email) in
- XCTAssert(email == "unit_tester@manulife.com", "Email retrieved not matching PID.")
- })
- }
- })
- waitForExpectations(timeout: 4, handler: {
- (error) in
- if let error = error {
- XCTFail("waitForExpectationsWithTimeout errored: \(error)")
- }
- })
- }
- // Test Cloud functions
- func testCloud() {
- let expect = expectation(description: "Upload and download should succeed")
- let image = #imageLiteral(resourceName: "avatar")
- let thumbnailImage = image.resizeImage(CGFloat(60), opaque: false)
- guard let avatarData = UIImageJPEGRepresentation(image, 0.8),
- let thumbnailData = UIImageJPEGRepresentation(thumbnailImage, 0.8) else {
- return
- }
- self.user.login(email: "joseph_reusing@manulife.com", password: "123456", completion: {
- (error) in
- if error == nil {
- self.profiles.upload(avatarData: avatarData, thumbnailData: thumbnailData, completion: {
- (error) in
- XCTAssert(error == nil, "Failed to upload Avatar.")
- self.profiles.download(completion: {
- (image, error) in
- XCTAssert(error == nil, "Failed to download Avatar.")
- self.profiles.deleteMyAvatar(completion: {
- (error) in
- XCTAssert(error != nil, "Should not be able to delete Avatar.")
- expect.fulfill()
- })
- })
- })
- }
- })
- waitForExpectations(timeout: 10, handler: {
- (error) in
- if let error = error {
- XCTFail("waitForExpectationsWithTimeout errored: \(error)")
- }
- })
- }
- // Test loading profile thumbnail
- func testThumbnail() {
- let expect = expectation(description: "Loading thumbnail should succeed.")
- self.user.login(email: "joseph_reusing@manulife.com", password: "123456", completion: {
- (error) in
- if error == nil {
- self.profiles.loadMyProfile {
- if let myProfile = self.profiles.myProfile {
- myProfile.loadThumbnail(completion: {
- (image, error) in
- XCTAssert(error == nil, "Failed to load thumbnail.")
- myProfile.hasAvatar = false
- myProfile.loadThumbnail(completion: {
- (image, error) in
- XCTAssert(image == nil, "Should not load image.")
- myProfile.hasAvatar = true
- expect.fulfill()
- })
- })
- }
- }
- }
- })
- waitForExpectations(timeout: 10, handler: {
- (error) in
- if let error = error {
- XCTFail("waitForExpectationsWithTimeout errored: \(error)")
- }
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement