2024-07-22 18:00:51 +08:00
|
|
|
package repository
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"caatsm/internal/domain"
|
2024-07-23 11:29:12 +08:00
|
|
|
"context"
|
2024-07-22 18:00:51 +08:00
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
2024-07-23 11:29:12 +08:00
|
|
|
"github.com/hasura/go-graphql-client"
|
2024-07-22 18:00:51 +08:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestConfig(t *testing.T) {
|
|
|
|
|
RegisterFailHandler(Fail)
|
|
|
|
|
RunSpecs(t, "Repositories Suite")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ = Describe("Repositories", func() {
|
2024-07-23 11:29:12 +08:00
|
|
|
Context("Just a simple test", func() {
|
|
|
|
|
|
|
|
|
|
// Define a struct for the mutation input to match the expected GraphQL input
|
|
|
|
|
// Define a struct for the mutation input to match the expected GraphQL input
|
|
|
|
|
type aviation_user_insert_input struct {
|
|
|
|
|
Name graphql.String `json:"name"`
|
|
|
|
|
Email graphql.String `json:"email"`
|
|
|
|
|
UpdateAt graphql.String `json:"update_at"` // Use string for timestamp
|
|
|
|
|
}
|
|
|
|
|
// Get the current time in RFC3339 format
|
|
|
|
|
currentTime := time.Now().Format(time.RFC3339)
|
|
|
|
|
|
|
|
|
|
input := aviation_user_insert_input{
|
|
|
|
|
Name: graphql.String("new"),
|
|
|
|
|
Email: graphql.String("2@2.com"),
|
|
|
|
|
UpdateAt: graphql.String(currentTime), // Use formatted string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Define the mutation
|
|
|
|
|
var mutation struct {
|
|
|
|
|
InsertAviationUserOne struct {
|
|
|
|
|
ID int `json:"id"`
|
|
|
|
|
Name string
|
|
|
|
|
} `graphql:"insert_aviation_user_one(object: $object)"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Define the mutation variables
|
|
|
|
|
// Define the mutation variables
|
|
|
|
|
variables := map[string]interface{}{
|
|
|
|
|
"object": input,
|
|
|
|
|
}
|
|
|
|
|
// Define the mutation
|
|
|
|
|
|
|
|
|
|
client := graphql.NewClient("http://localhost:8080/v1/graphql", nil)
|
|
|
|
|
|
|
|
|
|
err := client.Mutate(context.Background(), &mutation, variables)
|
|
|
|
|
It("should not error", func() {
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("name should be new", func() {
|
|
|
|
|
Expect(mutation.InsertAviationUserOne.Name).To(Equal("new"))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
2024-07-22 18:00:51 +08:00
|
|
|
Context("Hasura Repository", func() {
|
|
|
|
|
// var repository *HasuraRepository
|
|
|
|
|
var uuid = "uuid"
|
|
|
|
|
// BeforeEach(func() {
|
|
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
It("should mutate a parsed message", func() {
|
|
|
|
|
repository := NewHasuraRepo("http://localhost:8080/v1/graphql", "aviation-test")
|
|
|
|
|
parseMessage := &domain.ParsedMessage{
|
|
|
|
|
Uuid: uuid,
|
|
|
|
|
MessageID: "message_id",
|
|
|
|
|
DateTime: "date_time",
|
|
|
|
|
PriorityIndicator: "priority_indicator",
|
|
|
|
|
PrimaryAddress: "primary_address",
|
|
|
|
|
SecondaryAddresses: []string{"secondary_addresses"},
|
|
|
|
|
Originator: "originator",
|
|
|
|
|
OriginatorDateTime: "originator_date_time",
|
|
|
|
|
Category: "category",
|
|
|
|
|
BodyAndFooter: "body_and_footer",
|
2024-07-23 11:29:12 +08:00
|
|
|
// BodyData: &interface{},
|
|
|
|
|
ReceivedAt: time.Now(),
|
2024-07-22 18:00:51 +08:00
|
|
|
}
|
|
|
|
|
err := repository.InsertParsedMessage(parseMessage)
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|