Tusker/TuskerUITests/API Mocks/APIMocks.swift

78 lines
2.5 KiB
Swift
Raw Normal View History

2019-12-31 11:40:56 -05:00
//
// APIMocks.swift
// TuskerUITests
//
// Created by Shadowfacts on 12/30/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Foundation
import Ambassador
fileprivate let notFound = ["error": "Record not found"]
extension Router {
func allRoutes() {
instanceRoutes()
accountRoutes()
timelineRoutes()
notificationRoutes()
}
func instanceRoutes() {
self["/api/v1/instance"] = JSONResponse(handler: { (_) in
return [
"description": "An instance description",
"max_toot_chars": 500,
"thumbnail": "http://localhost:8080/thumbnail.png",
"title": "Localhost",
"uri": "http://localhost:8080",
"version": "2.7.2",
"urls": [:]
]
})
}
func accountRoutes() {
let selfAccount: [String: Any] = [
"id": "1",
"username": "admin",
"acct": "admin",
"display_name": "Admin Account",
"locked": false,
"created_at": "2019-12-31T11:13:42.0Z",
"followers_count": 0,
"following_count": 0,
"statuses_count": 0,
"note": "My profile description.",
"url": "http://localhost:8080/users/admin",
"avatar": "http://localhost:8080/avatar/admin.jpg",
"avatar_static": "http://localhost:8080/avatar/admin.jpg",
"header": "http://localhost:8080/header/admin.jpg",
"header_static": "http://localhost:8080/header/admin.jpg",
"emojis": []
]
self["/api/v1/accounts/verify_credentials"] = JSONResponse(result: selfAccount)
self["/api/v1/accounts/\\d+/statuses"] = JSONResponse(result: [])
self["/api/v1/accounts/(\\d+)"] = DelegatingResponse { (env) in
let captures = env["ambassador.router_captures"] as! [String]
if captures[0] == "1" {
return JSONResponse(result: selfAccount)
} else {
return JSONResponse(statusCode: 404, statusMessage: "Not Found", result: notFound)
}
}
}
func timelineRoutes() {
let emptyTimeline: [Any] = []
self["/api/v1/timelines/home"] = JSONResponse(result: emptyTimeline)
self["/api/v1/timelines/public"] = JSONResponse(result: emptyTimeline)
}
func notificationRoutes() {
let emptyTimeline: [Any] = []
self["/api/v1/notifications"] = JSONResponse(result: emptyTimeline)
}
}