-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdd24a7
commit 86a127a
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// FlowTreeStructure.swift | ||
// | ||
// | ||
// Created by 朱浩宇 on 2023/4/29. | ||
// | ||
|
||
import Foundation | ||
|
||
extension MobbinAPI { | ||
func generateTreeSturctureFlow(from flows: [Flow], parent: String? = nil) -> [Tree<Flow>] { | ||
let topLevelFlows = flows.filter { | ||
$0.parentAppSectionId == parent | ||
} | ||
|
||
var res = [Tree<Flow>]() | ||
|
||
for topLevelFlow in topLevelFlows { | ||
let secondLevelFlows = flows.filter { | ||
$0.parentAppSectionId == topLevelFlow.id | ||
}.map { flow in | ||
Tree<Flow>.children(flow, generateTreeSturctureFlow(from: flows, parent: flow.id)) | ||
} | ||
|
||
res.append(.children(topLevelFlow, secondLevelFlows)) | ||
} | ||
|
||
return res | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Tree.swift | ||
// | ||
// | ||
// Created by 朱浩宇 on 2023/4/29. | ||
// | ||
|
||
import Foundation | ||
|
||
enum Tree<Item> { | ||
case children(Item, [Self]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ final class MobbinAPITests: XCTestCase { | |
|
||
func testLogin() async throws { | ||
let api = MobbinAPI(email: "[email protected]") | ||
let res = try await api.verify(code: "538917") | ||
let res = try await api.verify(code: "989496") | ||
print(api.token?.accessToken ?? "No Token") | ||
|
||
XCTAssertTrue(res) | ||
|
@@ -144,4 +144,16 @@ final class MobbinAPITests: XCTestCase { | |
|
||
try await api.delete(collection: collection) | ||
} | ||
|
||
func testGetiOSTreeFlows() async throws { | ||
let api = MobbinAPI(email: "[email protected]", token: Token(accessToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjgyODY2MDg4LCJzdWIiOiJkMmI0MTU5MC01M2E0LTRjNGQtOWQ5NC0wNmY1ZDcxODA3YzMiLCJlbWFpbCI6InpodWhhb3l1MDkwOUBpY2xvdWQuY29tIiwicGhvbmUiOiIiLCJhcHBfbWV0YWRhdGEiOnsicHJvdmlkZXIiOiJlbWFpbCIsInByb3ZpZGVycyI6WyJlbWFpbCJdfSwidXNlcl9tZXRhZGF0YSI6eyJhdmF0YXJfdXJsIjoiaHR0cHM6Ly91amFzbnRrZnBoeXdpenNkYWFwaS5zdXBhYmFzZS5jby9zdG9yYWdlL3YxL29iamVjdC9wdWJsaWMvdXNlci91c2VyX2F2YXRhcnMvYTcyZTgwNjQtZjdlYi00YjBhLTg0MWMtMzlhM2ExMGRmY2E0LmpwZWciLCJmdWxsX25hbWUiOiJVVFN6aHkifSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJvdHAiLCJ0aW1lc3RhbXAiOjE2ODI3Nzk2ODh9XSwic2Vzc2lvbl9pZCI6IjlhMGUwNzQwLTZhZGItNGJlMy1hNGFmLWQ5MDE0Y2FmNDYyZiJ9.nWNXx2FMjtzbEx7Ddr9LKC2v2NrP7Jbd2_b8tymkGho", refreshToken: "")) | ||
|
||
let apps = try await api.queryNextPage(nil) | ||
|
||
let flows = try await api.getiOSFlows(of: apps[0]) | ||
|
||
let tree = api.generateTreeSturctureFlow(from: flows) | ||
|
||
XCTAssertEqual(tree.count, 7) | ||
} | ||
} |