Skip to content

Commit

Permalink
Improve code coverage (#40)
Browse files Browse the repository at this point in the history
* Remove unused `Template.MarshalJSON` function

* Add tests for notifications APIs
  • Loading branch information
Acconut authored Dec 9, 2024
1 parent 830730d commit 4be8718
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
54 changes: 54 additions & 0 deletions notification_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package transloadit

import (
"strings"
"testing"
)

func TestListNotifications(t *testing.T) {
t.Parallel()

client := setup(t)
_, err := client.ListNotifications(ctx, &ListOptions{
PageSize: 3,
})

if err == nil {
t.Fatal("expected an error but got nil")
}

if !strings.Contains(err.Error(), "no longer available") {
t.Fatalf("unexpected error message: %v", err)
}
}

func TestReplayNotification(t *testing.T) {
t.Parallel()

client := setup(t)

// Create a Assembly to later replay its notifications
assembly := NewAssembly()
assembly.AddFile("image", "./fixtures/lol_cat.jpg")
assembly.AddStep("resize", map[string]interface{}{
"robot": "/image/resize",
"width": 75,
"height": 75,
})
assembly.NotifyURL = "https://transloadit.com/notify-url/"

info, err := client.StartAssembly(ctx, assembly)
if err != nil {
t.Fatal(err)
}

info, err = client.WaitForAssembly(ctx, info)
if err != nil {
t.Fatal(err)
}

// Test replay notification with custom notify URL
if err = client.ReplayNotification(ctx, info.AssemblyID, "https://transloadit.com/custom-notify"); err != nil {
t.Fatal(err)
}
}
15 changes: 0 additions & 15 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,6 @@ func (template *Template) UnmarshalJSON(b []byte) error {
return nil
}

func (template Template) MarshalJSON() ([]byte, error) {
var internal templateInternal

internal.Name = template.Name
internal.Content = template.Content
internal.ID = template.ID
if template.RequireSignatureAuth {
internal.RequireSignatureAuth = 1
} else {
internal.RequireSignatureAuth = 0
}

return json.Marshal(internal)
}

// CreateTemplate will save the provided template struct as a new template
// and return the ID of the new template.
func (client *Client) CreateTemplate(ctx context.Context, template Template) (string, error) {
Expand Down

0 comments on commit 4be8718

Please sign in to comment.