feat: add tests for webhook resolvers

This commit is contained in:
Lakhan Samani
2022-07-11 19:40:54 +05:30
parent 334041d0e4
commit 018a13ab3c
24 changed files with 381 additions and 31 deletions

View File

@@ -43,5 +43,7 @@ func DeleteWebhookResolver(ctx context.Context, params model.WebhookRequest) (*m
return nil, err
}
panic(fmt.Errorf("not implemented"))
return &model.Response{
Message: "Webhook deleted successfully",
}, nil
}

View File

@@ -63,7 +63,7 @@ func TestEndpointResolver(ctx context.Context, params model.TestEndpointRequest)
}
if params.EventName == constants.UserLoginWebhookEvent {
reqBody["login_method"] = constants.AuthRecipeMethodMagicLinkLogin
reqBody["auth_recipe"] = constants.AuthRecipeMethodMagicLinkLogin
}
requestBody, err := json.Marshal(reqBody)

View File

@@ -52,7 +52,7 @@ func UpdateWebhookResolver(ctx context.Context, params model.UpdateWebhookReques
CreatedAt: *webhook.CreatedAt,
}
if webhookDetails.EventName != utils.StringValue(params.EventName) {
if params.EventName != nil && webhookDetails.EventName != utils.StringValue(params.EventName) {
if isValid := validators.IsValidWebhookEventName(utils.StringValue(params.EventName)); !isValid {
log.Debug("invalid event name: ", utils.StringValue(params.EventName))
return nil, fmt.Errorf("invalid event name %s", utils.StringValue(params.EventName))
@@ -60,11 +60,11 @@ func UpdateWebhookResolver(ctx context.Context, params model.UpdateWebhookReques
webhookDetails.EventName = utils.StringValue(params.EventName)
}
if webhookDetails.EndPoint != utils.StringValue(params.Endpoint) {
if params.Endpoint != nil && webhookDetails.EndPoint != utils.StringValue(params.Endpoint) {
webhookDetails.EventName = utils.StringValue(params.EventName)
}
if webhookDetails.Enabled != utils.BoolValue(params.Enabled) {
if params.Enabled != nil && webhookDetails.Enabled != utils.BoolValue(params.Enabled) {
webhookDetails.Enabled = utils.BoolValue(params.Enabled)
}

View File

@@ -24,7 +24,9 @@ func WebhookLogsResolver(ctx context.Context, params model.ListWebhookLogRequest
return nil, fmt.Errorf("unauthorized")
}
pagination := utils.GetPagination(params.Pagination)
pagination := utils.GetPagination(&model.PaginatedInput{
Pagination: params.Pagination,
})
webhookLogs, err := db.Provider.ListWebhookLogs(ctx, pagination, utils.StringValue(params.WebhookID))
if err != nil {