-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathCustomListRepositoryTests.swift
80 lines (63 loc) · 2.17 KB
/
CustomListRepositoryTests.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
//
// CustomListRepositoryTests.swift
// MullvadVPNTests
//
// Created by Mojgan on 2024-02-07.
// Copyright © 2024 Mullvad VPN AB. All rights reserved.
//
@testable import MullvadSettings
@testable import MullvadVPN
import Network
import XCTest
class CustomListRepositoryTests: XCTestCase {
static let store = InMemorySettingsStore<SettingNotFound>()
private var repository = CustomListRepository()
override class func setUp() {
SettingsManager.unitTestStore = store
}
override class func tearDown() {
SettingsManager.unitTestStore = nil
}
override func tearDownWithError() throws {
repository.fetchAll().forEach {
repository.delete(id: $0.id)
}
}
func testFailedAddingDuplicateCustomList() throws {
let name = "Netflix"
let item = try XCTUnwrap(repository.create(name, locations: []))
XCTAssertThrowsError(try repository.create(item.name, locations: [])) { error in
XCTAssertEqual(error as? CustomRelayListError, CustomRelayListError.duplicateName)
}
}
func testAddingCustomList() throws {
let name = "Netflix"
let item = try XCTUnwrap(repository.create(name, locations: [
.country("SE"),
.city("SE", "Gothenburg"),
]))
let storedItem = repository.fetch(by: item.id)
XCTAssertEqual(storedItem, item)
}
func testDeletingCustomList() throws {
let name = "Netflix"
let item = try XCTUnwrap(repository.create(name, locations: [
.country("SE"),
.city("SE", "Gothenburg"),
]))
let storedItem = repository.fetch(by: item.id)
repository.delete(id: try XCTUnwrap(storedItem?.id))
XCTAssertNil(repository.fetch(by: item.id))
}
func testFetchingAllCustomList() throws {
_ = try XCTUnwrap(repository.create("Netflix", locations: [
.country("FR"),
.city("SE", "Gothenburg"),
]))
_ = try XCTUnwrap(repository.create("PS5", locations: [
.country("DE"),
.city("SE", "Gothenburg"),
]))
XCTAssertEqual(repository.fetchAll().count, 2)
}
}