Skip to content

Commit

Permalink
Merge pull request #5 from foomo/contentful-v0.5.1
Browse files Browse the repository at this point in the history
wip: revert regex
  • Loading branch information
franklinkim authored Apr 27, 2024
2 parents 1db51ce + 12e14a4 commit 94947ec
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
6 changes: 3 additions & 3 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ type Collection struct {
Includes map[string]interface{} `json:"includes"`
NextSyncURL string `json:"nextSyncUrl"`
NextPageURL string `json:"nextPageUrl"`
SyncToken string
SyncToken string `json:"syncToken"`
// Errors which occur in the contentful structure. They are not checked in
// this source code. Please do it yourself as you might still want to parse
// the result despite the error.
Errors []Error `json:"errors"`
// Details might also get set in case of errors.
Details *ErrorDetails
Details *ErrorDetails `json:"details"`
}

var syncTokenRegex = regexp.MustCompile(`sync_token=([a-zA-Z0-9\\-_]+)`)
var syncTokenRegex = regexp.MustCompile(`sync_token=([a-zA-Z0-9_\-]+)`)

// NewCollection initializes a new collection
func NewCollection(options *CollectionOptions) *Collection {
Expand Down
43 changes: 43 additions & 0 deletions collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,51 @@ import (
"os"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestSyncTokenRegex(t *testing.T) {
tests := []struct {
name string
url string
token string
}{
{
name: "empty",
url: "/spaces/yadj1kx9rmg0/sync?access_token=fdb4e7a3102747a02ea69ebac5e282b9e44d28fb340f778a4f5e788625a61abe",
token: "",
},
{
name: "a-zA-Z0-9",
url: "/spaces/yadj1kx9rmg0/sync?access_token=fdb4e7a3102747a02ea69ebac5e282b9e44d28fb340f778a4f5e788625a61abe&sync_token=w7Ese3kdwpMbMhhgw7QAUsKiw6bCi09CwpFYwpwywqVYw6DDh8OawrTDpWvCgMOhw6jCuAhxWX_CocOPwowhcsOzeEJSbcOvwrfDlCjDr8O1YzLDvi9FOTXCmsOqT8OFcHPDuFDCqyMMTsKNw7rDmsOqKcOnw7FCwpIfNMOcFMOxFnHCoCzDpAjCucOdwpwfw4YTK8Kpw6zCtDrChVQlNsO2ZybDnw",
token: "w7Ese3kdwpMbMhhgw7QAUsKiw6bCi09CwpFYwpwywqVYw6DDh8OawrTDpWvCgMOhw6jCuAhxWX_CocOPwowhcsOzeEJSbcOvwrfDlCjDr8O1YzLDvi9FOTXCmsOqT8OFcHPDuFDCqyMMTsKNw7rDmsOqKcOnw7FCwpIfNMOcFMOxFnHCoCzDpAjCucOdwpwfw4YTK8Kpw6zCtDrChVQlNsO2ZybDnw",
},
{
name: "a-zA-Z0-9_",
url: "/spaces/yadj1kx9rmg0/sync?access_token=fdb4e7a3102747a02ea69ebac5e282b9e44d28fb340f778a4f5e788625a61abe&sync_token=w_Ese3kdwpMbMhhgw7QAUsKiw6bCi09CwpFYwpwywqVYw6DDh8OawrTDpWvCgMOhw6jCuAhxWX_CocOPwowhcsOzeEJSbcOvwrfDlCjDr8O1YzLDvi9FOTXCmsOqT8OFcHPDuFDCqyMMTsKNw7rDmsOqKcOnw7FCwpIfNMOcFMOxFnHCoCzDpAjCucOdwpwfw4YTK8Kpw6zCtDrChVQlNsO2ZybDnw",
token: "w_Ese3kdwpMbMhhgw7QAUsKiw6bCi09CwpFYwpwywqVYw6DDh8OawrTDpWvCgMOhw6jCuAhxWX_CocOPwowhcsOzeEJSbcOvwrfDlCjDr8O1YzLDvi9FOTXCmsOqT8OFcHPDuFDCqyMMTsKNw7rDmsOqKcOnw7FCwpIfNMOcFMOxFnHCoCzDpAjCucOdwpwfw4YTK8Kpw6zCtDrChVQlNsO2ZybDnw",
},
{
name: "a-zA-Z0-9_-",
url: "/spaces/yadj1kx9rmg0/sync?access_token=fdb4e7a3102747a02ea69ebac5e282b9e44d28fb340f778a4f5e788625a61abe&sync_token=w_-se3kdwpMbMhhgw7QAUsKiw6bCi09CwpFYwpwywqVYw6DDh8OawrTDpWvCgMOhw6jCuAhxWX_CocOPwowhcsOzeEJSbcOvwrfDlCjDr8O1YzLDvi9FOTXCmsOqT8OFcHPDuFDCqyMMTsKNw7rDmsOqKcOnw7FCwpIfNMOcFMOxFnHCoCzDpAjCucOdwpwfw4YTK8Kpw6zCtDrChVQlNsO2ZybDnw",
token: "w_-se3kdwpMbMhhgw7QAUsKiw6bCi09CwpFYwpwywqVYw6DDh8OawrTDpWvCgMOhw6jCuAhxWX_CocOPwowhcsOzeEJSbcOvwrfDlCjDr8O1YzLDvi9FOTXCmsOqT8OFcHPDuFDCqyMMTsKNw7rDmsOqKcOnw7FCwpIfNMOcFMOxFnHCoCzDpAjCucOdwpwfw4YTK8Kpw6zCtDrChVQlNsO2ZybDnw",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
matches := syncTokenRegex.FindStringSubmatch(test.url)
if test.token == "" {
assert.Empty(t, matches)
} else {
require.Len(t, matches, 2)
assert.Equal(t, test.token, matches[1])
}
})
}
}

func TestNewCollection(t *testing.T) {
setup()
defer teardown()
Expand Down
8 changes: 8 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func TestQueryContentType(t *testing.T) {
assert.Equal(t, expected.Encode(), q.String())
}

func TestQueryInitial(t *testing.T) {
q := NewQuery().Initial("true")
expected := url.Values{}
expected.Set("initial", "true")
expected.Set("include", "0")
assert.Equal(t, expected.Encode(), q.String())
}

func TestQuerySelect(t *testing.T) {
q := NewQuery().
ContentType("ct").
Expand Down

0 comments on commit 94947ec

Please sign in to comment.