-
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.
Merge pull request #101 from gertrude-app/iosapp-events
- Loading branch information
Showing
67 changed files
with
1,025 additions
and
403 deletions.
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
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
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,25 @@ | ||
import IOSRoute | ||
|
||
extension LogIOSEvent: Resolver { | ||
static func resolve(with input: Input, in context: Context) async throws -> Output { | ||
let detail = "\(input.detail ?? ""), " + [ | ||
"device: `\(input.deviceType)`", | ||
"iOS: `\(input.iOSVersion)`", | ||
"vendorId: `\(input.vendorId?.lowercased ?? "(nil)")`", | ||
].joined(separator: ", ") | ||
|
||
try await context.db.create(InterestingEvent( | ||
eventId: input.eventId, | ||
kind: input.kind, | ||
context: "ios", | ||
detail: detail | ||
)) | ||
|
||
if context.env.mode == .prod { | ||
await with(dependency: \.slack) | ||
.sysLog("iOS app event: \(githubSearch(input.eventId)) \(detail)") | ||
} | ||
|
||
return .success | ||
} | ||
} |
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 @@ | ||
import IOSRoute | ||
import Vapor | ||
|
||
extension IOSRoute: RouteResponder { | ||
static func respond(to route: Self, in context: Context) async throws -> Response { | ||
switch route { | ||
case .logIOSEvent(let input): | ||
let output = try await LogIOSEvent.resolve(with: input, in: context) | ||
return try await self.respond(with: output) | ||
} | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
api/Tests/ApiTests/iOSPairResolvers/iOSResolverTests.swift
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,35 @@ | ||
import DuetSQL | ||
import IOSRoute | ||
import XCTest | ||
import XExpect | ||
|
||
@testable import Api | ||
|
||
final class iOSResolverTests: ApiTestCase { | ||
func testLogIOSEvent() async throws { | ||
let eventId = UUID().uuidString | ||
let vendorId = UUID() | ||
_ = try await LogIOSEvent.resolve( | ||
with: .init( | ||
eventId: eventId, | ||
kind: "event", | ||
deviceType: "iPhone", | ||
iOSVersion: "18.0.1", | ||
vendorId: vendorId, | ||
detail: "first launch" | ||
), | ||
in: .mock | ||
) | ||
|
||
let retrieved = try await InterestingEvent.query() | ||
.where(.eventId == eventId) | ||
.first(in: self.db) | ||
|
||
expect(retrieved.kind).toEqual("event") | ||
expect(retrieved.context).toEqual("ios") | ||
expect(retrieved.detail!).toContain("iPhone") | ||
expect(retrieved.detail!).toContain("18.0.1") | ||
expect(retrieved.detail!).toContain(vendorId.lowercased) | ||
expect(retrieved.detail!).toContain("first launch") | ||
} | ||
} |
Oops, something went wrong.