Skip to content

Commit 75cb62e

Browse files
committed
Fix tests
1 parent 8177aef commit 75cb62e

File tree

2 files changed

+52
-125
lines changed

2 files changed

+52
-125
lines changed

Tests/SharedTests/Publication/Services/Content Protection/ContentProtectionServiceTests.swift

+28-111
Original file line numberDiff line numberDiff line change
@@ -8,103 +8,6 @@
88
import XCTest
99

1010
class ContentProtectionServiceTests: XCTestCase {
11-
func testLinks() {
12-
let service = TestContentProtectionService()
13-
14-
XCTAssertEqual(
15-
service.links,
16-
[
17-
Link(
18-
href: "/~readium/content-protection",
19-
type: "application/vnd.readium.content-protection+json"
20-
),
21-
Link(
22-
href: "/~readium/rights/copy{?text,peek}",
23-
type: "application/vnd.readium.rights.copy+json",
24-
templated: true
25-
),
26-
Link(
27-
href: "/~readium/rights/print{?pageCount,peek}",
28-
type: "application/vnd.readium.rights.print+json",
29-
templated: true
30-
),
31-
]
32-
)
33-
}
34-
35-
func testGetContentProtection() throws {
36-
let service = TestContentProtectionService(
37-
isRestricted: true,
38-
error: Publication.OpeningError.notFound,
39-
credentials: "open sesame",
40-
rights: AllRestrictedUserRights(),
41-
name: .localized(["en": "DRM", "fr": "GDN"])
42-
)
43-
44-
let resource = service.get(link: Link(href: "/~readium/content-protection"))
45-
46-
XCTAssertEqual(
47-
try resource?.readAsString().get(),
48-
"""
49-
{"error":"File not found","isRestricted":true,"name":{"en":"DRM","fr":"GDN"},"rights":{"canCopy":false,"canPrint":false}}
50-
"""
51-
)
52-
}
53-
54-
func testGetCopy() {
55-
let rights = TestUserRights(copyCount: 10)
56-
let service = TestContentProtectionService(rights: rights)
57-
58-
XCTAssertEqual(try service.getCopy(text: "banana", peek: false).readAsString().get(), "{}")
59-
XCTAssertEqual(rights.copyCount, 4)
60-
XCTAssertThrowsError(try service.getCopy(text: "banana", peek: false).readAsString().get())
61-
XCTAssertEqual(rights.copyCount, 4)
62-
}
63-
64-
func testGetPeekCopy() {
65-
let rights = TestUserRights(copyCount: 10)
66-
let service = TestContentProtectionService(rights: rights)
67-
68-
XCTAssertEqual(try service.getCopy(text: "banana", peek: true).readAsString().get(), "{}")
69-
XCTAssertEqual(rights.copyCount, 10)
70-
XCTAssertEqual(try service.getCopy(text: "banana", peek: true).readAsString().get(), "{}")
71-
XCTAssertEqual(rights.copyCount, 10)
72-
}
73-
74-
func testGetCopyBadRequest() {
75-
let rights = TestUserRights(copyCount: 10)
76-
let service = TestContentProtectionService(rights: rights)
77-
78-
XCTAssertThrowsError(try service.get(link: Link(href: "/~readium/rights/copy?peek=query"))?.read().get())
79-
}
80-
81-
func testGetPrint() {
82-
let rights = TestUserRights(printCount: 10)
83-
let service = TestContentProtectionService(rights: rights)
84-
85-
XCTAssertEqual(try service.getPrint(pageCount: 6, peek: false).readAsString().get(), "{}")
86-
XCTAssertEqual(rights.printCount, 4)
87-
XCTAssertThrowsError(try service.getPrint(pageCount: 6, peek: false).readAsString().get())
88-
XCTAssertEqual(rights.printCount, 4)
89-
}
90-
91-
func testGetPeekPrint() {
92-
let rights = TestUserRights(printCount: 10)
93-
let service = TestContentProtectionService(rights: rights)
94-
95-
XCTAssertEqual(try service.getPrint(pageCount: 6, peek: true).readAsString().get(), "{}")
96-
XCTAssertEqual(rights.printCount, 10)
97-
XCTAssertEqual(try service.getPrint(pageCount: 6, peek: true).readAsString().get(), "{}")
98-
XCTAssertEqual(rights.printCount, 10)
99-
}
100-
101-
func testGetPrintBadRequest() {
102-
let rights = TestUserRights(printCount: 10)
103-
let service = TestContentProtectionService(rights: rights)
104-
105-
XCTAssertThrowsError(try service.get(link: Link(href: "/~readium/rights/print?peek=query"))?.read().get())
106-
}
107-
10811
func testGetUnknown() {
10912
let service = TestContentProtectionService()
11013

@@ -114,7 +17,7 @@ class ContentProtectionServiceTests: XCTestCase {
11417
}
11518

11619
/// The Publication helpers will use the `ContentProtectionService` if there's one.
117-
func testPublicationHelpers() {
20+
func testPublicationHelpers() async {
11821
let publication = makePublication(service: { _ in
11922
TestContentProtectionService(
12023
isRestricted: true,
@@ -129,29 +32,43 @@ class ContentProtectionServiceTests: XCTestCase {
12932
XCTAssertTrue(publication.isRestricted)
13033
XCTAssertNotNil(publication.protectionError)
13134
XCTAssertEqual(publication.credentials, "open sesame")
132-
XCTAssertFalse(publication.rights.canCopy)
133-
XCTAssertFalse(publication.rights.canCopy(text: String(repeating: "word", count: 99999)))
134-
XCTAssertFalse(publication.rights.copy(text: String(repeating: "word", count: 99999)))
135-
XCTAssertFalse(publication.rights.canPrint)
136-
XCTAssertFalse(publication.rights.canPrint(pageCount: 99999))
137-
XCTAssertFalse(publication.rights.print(pageCount: 99999))
35+
36+
let r1 = await publication.rights.canCopy(text: String(repeating: "word", count: 99999))
37+
XCTAssertFalse(r1)
38+
39+
let r2 = await publication.rights.copy(text: String(repeating: "word", count: 99999))
40+
XCTAssertFalse(r2)
41+
42+
let r3 = await publication.rights.canPrint(pageCount: 99999)
43+
XCTAssertFalse(r3)
44+
45+
let r4 = await publication.rights.print(pageCount: 99999)
46+
XCTAssertFalse(r4)
47+
13848
XCTAssertEqual(publication.protectionLocalizedName, .localized(["en": "DRM", "fr": "GDN"]))
13949
XCTAssertEqual(publication.protectionName, "DRM")
14050
}
14151

142-
func testPublicationHelpersFallbacks() {
52+
func testPublicationHelpersFallbacks() async {
14353
let publication = makePublication(service: nil)
14454

14555
XCTAssertFalse(publication.isProtected)
14656
XCTAssertFalse(publication.isRestricted)
14757
XCTAssertNil(publication.protectionError)
14858
XCTAssertNil(publication.credentials)
149-
XCTAssertTrue(publication.rights.canCopy)
150-
XCTAssertTrue(publication.rights.canCopy(text: String(repeating: "word", count: 99999)))
151-
XCTAssertTrue(publication.rights.copy(text: String(repeating: "word", count: 99999)))
152-
XCTAssertTrue(publication.rights.canPrint)
153-
XCTAssertTrue(publication.rights.canPrint(pageCount: 99999))
154-
XCTAssertTrue(publication.rights.print(pageCount: 99999))
59+
60+
let r1 = await publication.rights.canCopy(text: String(repeating: "word", count: 99999))
61+
XCTAssertTrue(r1)
62+
63+
let r2 = await publication.rights.copy(text: String(repeating: "word", count: 99999))
64+
XCTAssertTrue(r2)
65+
66+
let r3 = await publication.rights.canPrint(pageCount: 99999)
67+
XCTAssertTrue(r3)
68+
69+
let r4 = await publication.rights.print(pageCount: 99999)
70+
XCTAssertTrue(r4)
71+
15572
XCTAssertNil(publication.protectionLocalizedName)
15673
XCTAssertNil(publication.protectionName)
15774
}

Tests/SharedTests/Publication/Services/Content Protection/UserRightsTests.swift

+24-14
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,35 @@
88
import XCTest
99

1010
class UserRightsTests: XCTestCase {
11-
func testUnrestricted() {
11+
func testUnrestricted() async {
1212
let rights = UnrestrictedUserRights()
1313

14-
XCTAssertTrue(rights.canCopy)
15-
XCTAssertTrue(rights.canCopy(text: "1"))
16-
XCTAssertTrue(rights.copy(text: "1"))
17-
XCTAssertTrue(rights.canPrint)
18-
XCTAssertTrue(rights.canPrint(pageCount: 1))
19-
XCTAssertTrue(rights.print(pageCount: 1))
14+
let r1 = await rights.canCopy(text: "1")
15+
XCTAssertTrue(r1)
16+
17+
let r2 = await rights.copy(text: "1")
18+
XCTAssertTrue(r2)
19+
20+
let r3 = await rights.canPrint(pageCount: 1)
21+
XCTAssertTrue(r3)
22+
23+
let r4 = await rights.print(pageCount: 1)
24+
XCTAssertTrue(r4)
2025
}
2126

22-
func testAllRestricted() {
27+
func testAllRestricted() async {
2328
let rights = AllRestrictedUserRights()
2429

25-
XCTAssertFalse(rights.canCopy)
26-
XCTAssertFalse(rights.canCopy(text: "1"))
27-
XCTAssertFalse(rights.copy(text: "1"))
28-
XCTAssertFalse(rights.canPrint)
29-
XCTAssertFalse(rights.canPrint(pageCount: 1))
30-
XCTAssertFalse(rights.print(pageCount: 1))
30+
let r1 = await rights.canCopy(text: "1")
31+
XCTAssertFalse(r1)
32+
33+
let r2 = await rights.copy(text: "1")
34+
XCTAssertFalse(r2)
35+
36+
let r3 = await rights.canPrint(pageCount: 1)
37+
XCTAssertFalse(r3)
38+
39+
let r4 = await rights.print(pageCount: 1)
40+
XCTAssertFalse(r4)
3141
}
3242
}

0 commit comments

Comments
 (0)