Skip to content

Commit

Permalink
Update Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakr233 committed Mar 24, 2024
1 parent 0a8f48b commit e75634d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Foundation/Source/Tests/SourceTest/SourceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import XCTest
let temp = URL(fileURLWithPath: NSTemporaryDirectory())
.appendingPathComponent("wiki.qaq.Kimis.unit.test.\(UUID().uuidString)")

let testAccount = "test"
let testPassword = "test"

var source: Source!

class SourceTest: XCTestCase {
Expand All @@ -25,8 +28,8 @@ class SourceTest: XCTestCase {
host: "127.0.0.1",
port: 3555,
secured: false,
username: "test",
password: "test",
username: testAccount,
password: testPassword,
store: temp
) else {
XCTFail("login failed")
Expand Down
38 changes: 36 additions & 2 deletions Foundation/Source/Tests/SourceTest/Tests/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,51 @@ extension SourceTest {
XCTFail("unable to locate test users")
return
}

let comment = UUID().uuidString
dispatchAndWait {
let comment = UUID().uuidString
source.network.requestForReportAbuse(userId: user2.userId, comment: comment)
}

var token: String?

dispatchAndWait {
let url = source.network.base
.appendingPathComponent("api")
.appendingPathComponent("signin")
requestAndWait(
url: url.absoluteString,
allowFailure: false,
data: #"{"username":"\#(testAccount)","password":"\#(testPassword)"}"#.data(using: .utf8),
method: "POST"
) { data in
guard let data else {
XCTFail("failed to get json data")
return
}
let json = try? JSONSerialization.jsonObject(with: data, options: [])
guard let dict = json as? [String: Any] else {
XCTFail("failed to get json dict")
return
}
token = dict["i"] as? String
}
}

guard let token else {
XCTFail("failed to get token")
return
}

dispatchAndWait {
let url = source.network.base
.appendingPathComponent("api")
.appendingPathComponent("admin")
.appendingPathComponent("abuse-user-reports")
requestAndWait(
url: url.absoluteString,
allowFailure: false,
data: "{\"i\":\"\(source.receipt.token)\"}".data(using: .utf8),
data: "{\"i\":\"\(token)\"}".data(using: .utf8),
method: "POST"
) { data in
guard let data, let str = String(data: data, encoding: .utf8) else {
Expand Down

0 comments on commit e75634d

Please sign in to comment.