Skip to content

Commit

Permalink
chore: add a test for application/vnd.api+json media type
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-drzymala-form3 committed Jan 8, 2025
1 parent 5e36fe5 commit be6aa7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/app/proxy_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,22 @@ func (s *ProxyStage) and() *ProxyStage {
}

func (s *ProxyStage) a_pact_that_allows_any_names() *ProxyStage {
return s.a_pact_that_allows_any_names_for_content("application/json")
}

func (s *ProxyStage) a_pact_that_allows_any_names_for_content(contentType string) *ProxyStage {
s.pact.
AddInteraction().
UponReceiving(s.pactName).
WithRequest(dsl.Request{
Method: "POST",
Path: dsl.String("/users"),
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/json")},
Headers: dsl.MapMatcher{"Content-Type": dsl.String(contentType)},
Body: dsl.MapMatcher{"name": dsl.Regex("any", ".*")},
}).
WillRespondWith(dsl.Response{
Status: 200,
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/json")},
Headers: dsl.MapMatcher{"Content-Type": dsl.String(contentType)},
Body: map[string]string{"name": "any"},
})
return s
Expand Down
16 changes: 16 additions & 0 deletions internal/app/proxy_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"fmt"
"net/http"
"testing"

Expand Down Expand Up @@ -95,6 +96,21 @@ func TestConstraintHeaderMatch(t *testing.T) {
pact_can_be_generated()
}

func TestConstraintHeaderMatchJSONAPIContent(t *testing.T) {
given, when, then := NewProxyStage(t)

given.
a_pact_that_allows_any_names_for_content("application/vnd.api+json").and().
a_content_type_constraint_is_added("application/vnd.api+json")

when.
n_requests_are_sent_using_the_body_and_content_type(1, fmt.Sprintf(`{"name":"%s"}`, "sam"), "application/vnd.api+json")

then.
pact_verification_is_successful().and().
pact_can_be_generated()
}

func TestConstraintHeaderDoesntMatch(t *testing.T) {
given, when, then := NewProxyStage(t)

Expand Down

0 comments on commit be6aa7d

Please sign in to comment.