Skip to content

Commit

Permalink
feat(testutils): add test utility functions for creating and parsing …
Browse files Browse the repository at this point in the history
…content data

The `testutils` package now includes two utility functions. The
`NewStoreContent` function creates a new `content.NewContentAttributes`
object with predefined values for testing purposes. It takes in the name
and namespace as parameters and returns the created object. The
`ContentFromStore` function parses a JSON string representing content
data and returns a `ContentJSON` object. This function is useful for
testing scenarios where content data needs to be parsed and validated.
  • Loading branch information
cybersiddhu committed Nov 6, 2023
1 parent e93b805 commit 2c3695f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions internal/testutils/testutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package testutils

import (
"encoding/json"
"fmt"

"github.com/dictyBase/go-genproto/dictybaseapis/content"
"github.com/dictyBase/modware-content/internal/model"
)

type ContentJSON struct {
Paragraph string `json:"paragraph"`
Text string `json:"text"`
}

func NewStoreContent(name, namespace string) *content.NewContentAttributes {
cdata, _ := json.Marshal(&ContentJSON{
Paragraph: "paragraph",
Text: "text",
})

return &content.NewContentAttributes{
Name: name,
Namespace: namespace,
CreatedBy: "[email protected]",
Content: string(cdata),
Slug: model.Slugify(fmt.Sprintf("%s %s", name, namespace)),
}
}

func ContentFromStore(jsctnt string) (*ContentJSON, error) {
ctnt := &ContentJSON{}
err := json.Unmarshal([]byte(jsctnt), ctnt)
if err != nil {
return ctnt, fmt.Errorf("error in unmarshing json %s", err)
}

return ctnt, nil
}

0 comments on commit 2c3695f

Please sign in to comment.