GODT-2170: Use client-side draft update in integration tests

This commit is contained in:
James Houlahan
2022-12-02 12:47:12 +01:00
parent 01c7daaba7
commit 7bc608ce6c
7 changed files with 63 additions and 54 deletions

View File

@ -230,36 +230,28 @@ func (t *testCtx) getMBoxID(userID string, name string) string {
// getDraftID will return the API ID of draft message with draftIndex, where
// draftIndex is similar to sequential ID i.e. 1 represents the first message
// of draft folder sorted by API creation time.
func (t *testCtx) getDraftID(username string, draftIndex int) string {
if draftIndex < 1 {
panic(fmt.Sprintf("draft index suppose to be non-zero positive integer, but have %d", draftIndex))
}
func (t *testCtx) getDraftID(username string, draftIndex int) (string, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var draftID string
if err := t.withClient(ctx, username, func(ctx context.Context, client *proton.Client) error {
messages, err := client.GetMessageMetadata(
ctx, proton.MessageFilter{LabelID: proton.DraftsLabel},
)
messages, err := client.GetMessageMetadata(ctx, proton.MessageFilter{LabelID: proton.DraftsLabel})
if err != nil {
panic(err)
}
if len(messages) < draftIndex {
panic("draft index too high")
return fmt.Errorf("failed to get message metadata: %w", err)
} else if len(messages) < draftIndex {
return fmt.Errorf("draft index %d is out of range", draftIndex)
}
draftID = messages[draftIndex-1].ID
return nil
}); err != nil {
panic(err)
return "", err
}
return draftID
return draftID, nil
}
func (t *testCtx) getLastCall(method, pathExp string) (server.Call, error) {