From 8896706560c891c2ba3d4052b31e46f02238e326 Mon Sep 17 00:00:00 2001 From: Jared Henderson Date: Sat, 21 Oct 2023 14:58:38 -0400 Subject: [PATCH] api: handle beta installs w/ stable release channel logic --- .../MacApp/Resolvers/LatestAppVersion.swift | 24 ++++++++++++------- .../CheckInResolverTests.swift | 20 ++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/api/Sources/Api/PairQL/MacApp/Resolvers/LatestAppVersion.swift b/api/Sources/Api/PairQL/MacApp/Resolvers/LatestAppVersion.swift index 44c1edfd..0f4e67c9 100644 --- a/api/Sources/Api/PairQL/MacApp/Resolvers/LatestAppVersion.swift +++ b/api/Sources/Api/PairQL/MacApp/Resolvers/LatestAppVersion.swift @@ -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)) + ) + } } } diff --git a/api/Tests/ApiTests/MacappPairResolvers/CheckInResolverTests.swift b/api/Tests/ApiTests/MacappPairResolvers/CheckInResolverTests.swift index e317881f..abc73a67 100644 --- a/api/Tests/ApiTests/MacappPairResolvers/CheckInResolverTests.swift +++ b/api/Tests/ApiTests/MacappPairResolvers/CheckInResolverTests.swift @@ -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