feat(GODT-2554): Compute telemetry availability from API UserSettings.

This commit is contained in:
Romain Le Jeune
2023-04-13 08:06:48 +00:00
parent c7ae239350
commit 3928ed08f6
7 changed files with 88 additions and 0 deletions

View File

@ -153,6 +153,8 @@ func TestFeatures(testingT *testing.T) {
ctx.Step(`^bridge sends an update not available event$`, s.bridgeSendsAnUpdateNotAvailableEvent)
ctx.Step(`^bridge sends a forced update event$`, s.bridgeSendsAForcedUpdateEvent)
ctx.Step(`^bridge reports a message with "([^"]*)"$`, s.bridgeReportsMessage)
ctx.Step(`^bridge telemetry feature is enabled$`, s.bridgeTelemetryFeatureEnabled)
ctx.Step(`^bridge telemetry feature is disabled$`, s.bridgeTelemetryFeatureDisabled)
// ==== FRONTEND ====
ctx.Step(`^frontend sees that bridge is version "([^"]*)"$`, s.frontendSeesThatBridgeIsVersion)
@ -166,6 +168,7 @@ func TestFeatures(testingT *testing.T) {
ctx.Step(`^user "([^"]*)" is listed but not connected$`, s.userIsListedButNotConnected)
ctx.Step(`^user "([^"]*)" is not listed$`, s.userIsNotListed)
ctx.Step(`^user "([^"]*)" finishes syncing$`, s.userFinishesSyncing)
ctx.Step(`^user "([^"]*)" has telemetry set to (\d+)$`, s.userHasTelemetrySetTo)
// ==== IMAP ====
ctx.Step(`^user "([^"]*)" connects IMAP client "([^"]*)"$`, s.userConnectsIMAPClient)

View File

@ -284,6 +284,22 @@ func (s *scenario) bridgeReportsMessage(message string) error {
return nil
}
func (s *scenario) bridgeTelemetryFeatureEnabled() error {
return s.checkTelemetry(true)
}
func (s *scenario) bridgeTelemetryFeatureDisabled() error {
return s.checkTelemetry(false)
}
func (s *scenario) checkTelemetry(expect bool) error {
res := s.t.bridge.ComputeTelemetry()
if res != expect {
return fmt.Errorf("expected telemetry feature %v but got %v ", expect, res)
}
return nil
}
func (s *scenario) theUserHidesAllMail() error {
return s.t.bridge.SetShowAllMail(false)
}

View File

@ -0,0 +1,18 @@
Feature: Bridge send usage metrics
Background:
Given there exists an account with username "[user:user1]" and password "password"
And there exists an account with username "[user:user2]" and password "password"
And bridge starts
Scenario: Telemetry availability - No user
Then bridge telemetry feature is enabled
Scenario: Telemetry availability - Multi user
When the user logs in with username "[user:user1]" and password "password"
And user "[user:user1]" finishes syncing
Then bridge telemetry feature is enabled
When the user logs in with username "[user:user2]" and password "password"
And user "[user:user2]" finishes syncing
When user "[user:user2]" has telemetry set to 0
Then bridge telemetry feature is disabled

View File

@ -414,6 +414,18 @@ func (s *scenario) userFinishesSyncing(username string) error {
return s.bridgeSendsSyncStartedAndFinishedEventsForUser(username)
}
func (s *scenario) userHasTelemetrySetTo(username string, telemetry int) error {
return s.t.withClientPass(context.Background(), username, s.t.getUserByName(username).userPass, func(ctx context.Context, c *proton.Client) error {
var req proton.SetTelemetryReq
req.Telemetry = proton.SettingsBool(telemetry)
_, err := c.SetUserSettingsTelemetry(ctx, req)
if err != nil {
return err
}
return nil
})
}
func (s *scenario) addAdditionalAddressToAccount(username, address string, disabled bool) error {
userID := s.t.getUserByName(username).getUserID()