Skip to content

Commit

Permalink
Moves tests around
Browse files Browse the repository at this point in the history
Thanks to Codable, there's no custom parser for the models anymore. The old
parser test can be moved to the test of the models instead.
  • Loading branch information
ornithocoder committed Jan 2, 2018
1 parent 339016d commit 43144bf
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 326 deletions.
10 changes: 10 additions & 0 deletions Tests/MastodonKitTests/Fixtures/Lists.json
@@ -0,0 +1,10 @@
[
{
"id": "42",
"title": "nice list title"
},
{
"id": "43",
"title": "another nice list title"
}
]
19 changes: 19 additions & 0 deletions Tests/MastodonKitTests/Models/AccountTests.swift
Expand Up @@ -30,4 +30,23 @@ class AccountTests: XCTestCase {
XCTAssertEqual(account?.followingCount, 52)
XCTAssertEqual(account?.statusesCount, 420)
}

func testAccountWithInvalidData() {
let parsed = try? Account.decode(data: Data())

XCTAssertNil(parsed)
}

func testAccountsFromJSON() {
let fixture = try! Fixture.load(fileName: "Fixtures/Accounts.json")
let parsed = try? [Account].decode(data: fixture)

XCTAssertEqual(parsed?.count, 2)
}

func testAccountsWithInvalidData() {
let parsed = try? [Account].decode(data: Data())

XCTAssertNil(parsed)
}
}
6 changes: 6 additions & 0 deletions Tests/MastodonKitTests/Models/CardTests.swift
Expand Up @@ -19,4 +19,10 @@ class CardTests: XCTestCase {
XCTAssertEqual(card?.description, "Card description")
XCTAssertEqual(card?.image, URL(string: "http://lorempixel.com/200/200/cats/1/"))
}

func testCardWithInvalidData() {
let parsed = try? Card.decode(data: Data())

XCTAssertNil(parsed)
}
}
6 changes: 6 additions & 0 deletions Tests/MastodonKitTests/Models/ClientApplicationTests.swift
Expand Up @@ -19,4 +19,10 @@ class ClientApplicationTests: XCTestCase {
XCTAssertEqual(application?.clientID, "very_long_client_id")
XCTAssertEqual(application?.clientSecret, "very_long_client_secret")
}

func testClientApplicationWithInvalidData() {
let parsed = try? ClientApplication.decode(data: Data())

XCTAssertNil(parsed)
}
}
6 changes: 6 additions & 0 deletions Tests/MastodonKitTests/Models/ContextTests.swift
Expand Up @@ -17,4 +17,10 @@ class ContextTests: XCTestCase {
XCTAssertEqual(context?.ancestors.count, 1)
XCTAssertEqual(context?.descendants.count, 1)
}

func testContextWithInvalidData() {
let parsed = try? Context.decode(data: Data())

XCTAssertNil(parsed)
}
}
28 changes: 28 additions & 0 deletions Tests/MastodonKitTests/Models/EmptyTests.swift
Expand Up @@ -16,4 +16,32 @@ class EmptyTests: XCTestCase {

XCTAssertNotNil(empty)
}

func testEmptyWithEmptyDictionary() {
let fixture = "[:]".data(using: .utf8)!
let parsed = try? Empty.decode(data: fixture)

XCTAssertNil(parsed)
}

func testEmptyWithNonEmptyDictionary() {
let fixture = "[\"foo\": \"bar\"]".data(using: .utf8)!
let parsed = try? Empty.decode(data: fixture)

XCTAssertNil(parsed)
}

func testEmptyWithEmptyString() {
let fixture = "".data(using: .utf8)!
let parsed = try? Empty.decode(data: fixture)

XCTAssertNil(parsed)
}

func testEmptyWithString() {
let fixture = "foo".data(using: .utf8)!
let parsed = try? Empty.decode(data: fixture)

XCTAssertNil(parsed)
}
}
6 changes: 6 additions & 0 deletions Tests/MastodonKitTests/Models/InstanceTests.swift
Expand Up @@ -20,4 +20,10 @@ class InstanceTests: XCTestCase {
XCTAssertEqual(instance?.email, "wunderbar email")
XCTAssertEqual(instance?.version, "1.2.3")
}

func testInstanceWithInvalidData() {
let parsed = try? Instance.decode(data: Data())

XCTAssertNil(parsed)
}
}
7 changes: 7 additions & 0 deletions Tests/MastodonKitTests/Models/ListTests.swift
Expand Up @@ -17,4 +17,11 @@ class ListTests: XCTestCase {
XCTAssertEqual(list?.id, "42")
XCTAssertEqual(list?.title, "nice list title")
}

func testListsFromJSON() {
let fixture = try! Fixture.load(fileName: "Fixtures/Lists.json")
let parsed = try? [List].decode(data: fixture)

XCTAssertEqual(parsed?.count, 2)
}
}
6 changes: 6 additions & 0 deletions Tests/MastodonKitTests/Models/LoginSettingsTests.swift
Expand Up @@ -19,4 +19,10 @@ class LoginSettingsTests: XCTestCase {
XCTAssertEqual((loginSettings?.scopes)!, [.read, .write])
XCTAssertEqual(loginSettings?.createdAt, 1492249031)
}

func testLoginSettingsWithInvalidData() {
let parsed = try? LoginSettings.decode(data: Data())

XCTAssertNil(parsed)
}
}
19 changes: 19 additions & 0 deletions Tests/MastodonKitTests/Models/NotificationTests.swift
Expand Up @@ -20,4 +20,23 @@ class NotificationTests: XCTestCase {
XCTAssertNotNil(notification?.account)
XCTAssertNotNil(notification?.status)
}

func testNotificationWithInvalidData() {
let parsed = try? MastodonKit.Notification.decode(data: Data())

XCTAssertNil(parsed)
}

func testNotificationsFromJSON() {
let fixture = try! Fixture.load(fileName: "Fixtures/Notifications.json")
let parsed = try? [MastodonKit.Notification].decode(data: fixture)

XCTAssertEqual(parsed?.count, 2)
}

func testNotificationsWithInvalidData() {
let parsed = try? [MastodonKit.Notification].decode(data: Data())

XCTAssertNil(parsed)
}
}
19 changes: 19 additions & 0 deletions Tests/MastodonKitTests/Models/RelationshipTests.swift
Expand Up @@ -23,4 +23,23 @@ class RelationshipTests: XCTestCase {
XCTAssertFalse((relationship?.requested)!)
XCTAssertTrue((relationship?.domainBlocking)!)
}

func testRelationshipWithInvalidData() {
let parsed = try? Relationship.decode(data: Data())

XCTAssertNil(parsed)
}

func testRelationshipsFromJSON() {
let fixture = try! Fixture.load(fileName: "Fixtures/Relationships.json")
let parsed = try? [Relationship].decode(data: fixture)

XCTAssertEqual(parsed?.count, 2)
}

func testRelationshipsWithInvalidData() {
let parsed = try? [Relationship].decode(data: Data())

XCTAssertNil(parsed)
}
}
19 changes: 19 additions & 0 deletions Tests/MastodonKitTests/Models/ReportTests.swift
Expand Up @@ -17,4 +17,23 @@ class ReportTests: XCTestCase {
XCTAssertEqual(report?.id, "42")
XCTAssertEqual(report?.actionTaken, "account deleted")
}

func testReportWithInvalidData() {
let parsed = try? Report.decode(data: Data())

XCTAssertNil(parsed)
}

func testReportsFromJSON() {
let fixture = try! Fixture.load(fileName: "Fixtures/Reports.json")
let parsed = try? [Report].decode(data: fixture)

XCTAssertEqual(parsed?.count, 2)
}

func testReportsWithInvalidData() {
let parsed = try? [Report].decode(data: Data())

XCTAssertNil(parsed)
}
}
2 changes: 1 addition & 1 deletion Tests/MastodonKitTests/Models/ResultsTests.swift
Expand Up @@ -19,7 +19,7 @@ class ResultsTests: XCTestCase {
XCTAssertEqual((results?.hashtags)!, ["one", "two", "three"])
}

func testResultsFromEmptyJSON() {
func testResultsWithInvalidData() {
let results = try? Results.decode(data: Data())

XCTAssertNil(results)
Expand Down
19 changes: 19 additions & 0 deletions Tests/MastodonKitTests/Models/StatusTests.swift
Expand Up @@ -67,4 +67,23 @@ class StatusTests: XCTestCase {
XCTAssertEqual(status?.language, "fr")
XCTAssertTrue((status?.pinned)!)
}

func testStatusWithInvalidData() {
let parsed = try? Status.decode(data: Data())

XCTAssertNil(parsed)
}

func testStatusesFromJSON() {
let fixture = try! Fixture.load(fileName: "Fixtures/Timeline.json")
let parsed = try? [Status].decode(data: fixture)

XCTAssertEqual(parsed?.count, 2)
}

func testStatusesWithInvalidData() {
let parsed = try? [Status].decode(data: Data())

XCTAssertNil(parsed)
}
}
29 changes: 29 additions & 0 deletions Tests/MastodonKitTests/Models/StringsTests.swift
@@ -0,0 +1,29 @@
//
// RequestParsersTests.swift
// MastodonKit
//
// Created by Ornithologist Coder on 5/17/17.
// Copyright © 2017 MastodonKit. All rights reserved.
//

import XCTest
@testable import MastodonKit

class StringsTests: XCTestCase {
func testDomainBlocksFromValidJSON() {
let fixture = try! Fixture.load(fileName: "Fixtures/DomainBlocks.json")
let parsed = try? [String].decode(data: fixture)

XCTAssertEqual(parsed?.count, 3)

XCTAssertTrue(parsed!.contains("toto"))
XCTAssertTrue(parsed!.contains("foo"))
XCTAssertTrue(parsed!.contains("bar"))
}

func testDomainBlocksWithInvalidData() {
let parsed = try? [String].decode(data: Data())

XCTAssertNil(parsed)
}
}

0 comments on commit 43144bf

Please sign in to comment.