This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
/
AssetsSpec.swift
125 lines (107 loc) · 4.48 KB
/
AssetsSpec.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// AssetsSpec.swift
// Prism
//
// Created by Shai Mishali on 22/05/2019.
// Copyright © 2019 Gett. All rights reserved.
//
import Foundation
import Quick
import Nimble
import SnapshotTesting
@testable import PrismCore
@testable import ZeplinAPI
class AssetsSpec: QuickSpec {
override func spec() {
describe("assets snapshot") {
it("is valid") {
let assetsResult = Prism(jwtToken: "fake").mock(type: .successfulProject)
let assets = try! assetsResult.get()
assertSnapshot(matching: "\(assets.debugDescription)",
as: .lines,
named: "assets snapshot is valid")
}
}
describe("failed server response") {
it("should return failed result") {
let projectResult = Prism(jwtToken: "fake").mock(type: .failure)
guard case .failure = projectResult else {
fail("Expected error, got \(projectResult)")
return
}
expect(try? projectResult.get()).to(beNil())
}
}
describe("duplicate asset identities") {
it("should fail with error") {
let result = Prism(jwtToken: "fake").mock(type: .duplicateAssets)
switch result {
case .failure(let error):
expect(error.description) == """
Duplicate colors found: green, mud, purple, teal
Duplicate text styles found: Base Heading, Body, Highlight
Duplicate spacings found: spacing-m, spacing-xl, spacing-xs, spacing-xxs
"""
default:
fail("Expected invalid project ID error, got \(String(describing: result))")
}
}
}
describe("invalid project ID causing invalid API URL") {
it("should fail with error") {
var result: Result<Assets, ZeplinAPI.Error>?
Prism(jwtToken: "dsadas").getAssets(for: .project(id: "|||")) { res in result = res }
switch result {
case .some(.failure(let error)):
expect(error.description.starts(with: "Failed constructing URL from path")).to(beTrue())
default:
fail("Expected invalid project ID error, got \(String(describing: result))")
}
}
}
describe("invalid styleguide ID causing invalid API URL") {
it("should fail with error") {
var result: Result<Assets, ZeplinAPI.Error>?
Prism(jwtToken: "dsadas").getAssets(for: .styleguide(id: "|||")) { res in result = res }
switch result {
case .some(.failure(let error)):
expect(error.description.starts(with: "Failed constructing URL from path")).to(beTrue())
default:
fail("Expected invalid styleguide ID error, got \(String(describing: result))")
}
}
}
describe("description") {
it("should not be empty") {
let projectResult = Prism(jwtToken: "fake").mock(type: .successfulProject)
let project = try! projectResult.get()
expect(project.description).toNot(beEmpty())
}
}
describe("owner description") {
it("should return correct id for either owner") {
let owners: [AssetOwner] = [
.project(id: "123"),
.styleguide(id: "321"),
.styleguide(id: "sg"),
.project(id: "pj")
]
expect(owners.map(\.description)).to(equal(["Project 123",
"Styleguide 321",
"Styleguide sg",
"Project pj"]))
}
}
describe("owner id") {
it("should return correct id for either owner") {
let owners: [AssetOwner] = [
.project(id: "123"),
.styleguide(id: "321"),
.styleguide(id: "sg"),
.project(id: "pj")
]
expect(owners.map(\.id)).to(equal(["123", "321", "sg", "pj"]))
}
}
}
}