From 4b62f5d61c114c92cac6fc76cc3acf8b442720c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Dimja=C5=A1evi=C4=87?= Date: Tue, 19 Dec 2023 16:49:04 +0100 Subject: [PATCH] Test: A provider creation helper --- integration/test/SetupHelpers.hs | 25 +++++++++++++++++++++++ integration/test/Test/Services.hs | 33 +++++++++++-------------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/integration/test/SetupHelpers.hs b/integration/test/SetupHelpers.hs index be86bbfc69f..0dbcfed6389 100644 --- a/integration/test/SetupHelpers.hs +++ b/integration/test/SetupHelpers.hs @@ -245,3 +245,28 @@ getOne2OneConversation user1 user2 cnvState = do qIds <- for others (%. "qualified_id") pure $ qIds == users && t head <$> filterM (isWith [user2]) l + +-- | Create a provider, get an activation code, activate the provider and log it +-- in. The return value is the created provider. +setupProvider :: + ( HasCallStack, + MakesValue user + ) => + user -> + NewProvider -> + App Value +setupProvider u np@(NewProvider {..}) = do + dom <- objDomain u + provider <- newProvider u np + pass <- provider %. "password" & asString + (key, code) <- do + pair <- + getProviderActivationCodeInternal dom newProviderEmail `bindResponse` \resp -> do + resp.status `shouldMatchInt` 200 + resp.json + k <- pair %. "key" & asString + c <- pair %. "code" & asString + pure (k, c) + activateProvider dom key code + void $ loginProvider dom newProviderEmail pass + pure provider diff --git a/integration/test/Test/Services.hs b/integration/test/Test/Services.hs index 25b1900870e..5d163ddf73d 100644 --- a/integration/test/Test/Services.hs +++ b/integration/test/Test/Services.hs @@ -18,7 +18,6 @@ module Test.Services where import API.Brig -import API.BrigInternal import API.Common import SetupHelpers import Testlib.Prelude @@ -28,26 +27,16 @@ testUpdateServiceUpdateAcceptHeader = do let dom = OwnDomain email <- randomEmail alice <- randomUser dom def - provider <- newProvider alice def {newProviderEmail = email} - providerId <- provider %. "id" & asString - pass <- provider %. "password" & asString - (key, code) <- do - pair <- - getProviderActivationCodeInternal dom email `bindResponse` \resp -> do - resp.status `shouldMatchInt` 200 - resp.json - k <- pair %. "key" & asString - c <- pair %. "code" & asString - pure (k, c) - activateProvider dom key code - void $ loginProvider dom email pass - service <- newService dom providerId def - serviceId <- service %. "id" + provider <- setupProvider alice def {newProviderEmail = email} + pId <- provider %. "id" & asString + service <- newService dom pId def + sIs <- service %. "id" void $ - updateService - dom - providerId - serviceId - (Just "application/json") - (Just "brand new service") + updateService dom pId sIs (Just "application/json") (Just "brand new service") + >>= getBody 200 + void $ + updateService dom pId sIs (Just "text/plain") (Just "even newer service") + >>= getBody 200 + void $ + updateService dom pId sIs Nothing (Just "really old service") >>= getBody 200