Skip to content

Commit

Permalink
api: handle beta installs w/ stable release channel logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredh159 committed Oct 21, 2023
1 parent 402f673 commit 8896706
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
24 changes: 16 additions & 8 deletions api/Sources/Api/PairQL/MacApp/Resolvers/LatestAppVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ extension LatestAppVersion: Resolver {
let current = Semver(input.currentVersion)!
var output = Output(semver: releases.first?.semver ?? "0.0.0")

// if they're on a beta/canary version ahead of their app release channel
// don't tell them there's an update to an older version
// this allows me to release "beta" versions to new customers without
// bothering existing users with an update
if current > Semver(output.semver)! {
output.semver = current.string
}

for release in releases {
output.semver = release.semver
if current < Semver(release.semver)!,
let pace = release.requirementPace,
output.pace == nil {
output.pace = .init(
nagOn: release.createdAt.advanced(by: .days(pace)),
requireOn: release.createdAt.advanced(by: .days(pace * 2))
)
if current < Semver(release.semver)! {
output.semver = release.semver
if let pace = release.requirementPace, output.pace == nil {
output.pace = .init(
nagOn: release.createdAt.advanced(by: .days(pace)),
requireOn: release.createdAt.advanced(by: .days(pace * 2))
)
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions api/Tests/ApiTests/MacappPairResolvers/CheckInResolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ final class CheckInResolverTests: ApiTestCase {
)
expect(output.keys.contains(.init(id: autoKey.id.rawValue, key: autoKey.key))).toBeTrue()
}

func testOnBetaAheadOfStable() async throws {
try await createReleases([
Release("1.0.0", pace: 10, createdAt: .epoch),
Release("1.1.0", pace: 10, createdAt: .epoch.advanced(by: .days(10))),
Release("2.0.0", channel: .beta, pace: 10, createdAt: .epoch.advanced(by: .days(20))),
])

let user = try await Entities.user().withDevice(adminDevice: {
$0.appReleaseChannel = .stable // set to stable, but they're on beta
})

let output = try await CheckIn.resolve(
with: .init(appVersion: "2.0.0", filterVersion: nil),
in: user.context
)

expect(output.updateReleaseChannel).toEqual(.stable)
expect(output.latestRelease.semver).toEqual("2.0.0")
}
}

// helpers
Expand Down

0 comments on commit 8896706

Please sign in to comment.