-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2026 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Test.TOTP.VersionGate where

import SetupHelpers
import Test.TOTP.Helpers (credentialIdPlaceholder)
import Testlib.Prelude

testTotpNotOnV18 :: (HasCallStack) => App ()
testTotpNotOnV18 :: HasCallStack => App ()
testTotpNotOnV18 = do
  alice <- Domain -> CreateUser -> App Value
forall domain.
(HasCallStack, MakesValue domain) =>
domain -> CreateUser -> App Value
randomUser Domain
OwnDomain CreateUser
forall a. Default a => a
def
  let routes =
        [ (String
"POST", String
"/self/totp"),
          (String
"GET", String
"/self/totp"),
          (String
"POST", String
"/self/totp/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
credentialIdPlaceholder String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"/activate"),
          (String
"PUT", String
"/self/totp/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
credentialIdPlaceholder),
          (String
"DELETE", String
"/self/totp/" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
credentialIdPlaceholder)
        ]
  for_ routes $ \(String
method, String
path) -> do
    req <- Value -> Service -> Versioned -> String -> App Request
forall user.
(HasCallStack, MakesValue user) =>
user -> Service -> Versioned -> String -> App Request
baseRequest Value
alice Service
Brig (Int -> Versioned
ExplicitVersion Int
18) String
path
    bindResponse (submit method (req & addJSONObject ["name" .= ("work phone" :: String)])) $ \Response
resp ->
      Response
resp.status Int -> [Value] -> App ()
forall a b.
(MakesValue a, MakesValue b, HasCallStack) =>
a -> b -> App ()
`shouldMatchOneOf` [Scientific -> Value
Number Scientific
404, Scientific -> Value
Number Scientific
405]