refactor: Update ARR body parsing logic
This commit is contained in:
@@ -4,7 +4,6 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
@@ -13,29 +12,29 @@ import (
|
||||
|
||||
// input type for inserting data into table "aviation.telegrams"
|
||||
type Aviation_telegrams_insert_input struct {
|
||||
Body_and_footer string `json:"body_and_footer"`
|
||||
Body_data json.RawMessage `json:"body_data"`
|
||||
Category string `json:"category"`
|
||||
Date_time string `json:"date_time"`
|
||||
Dispatched_at time.Time `json:"dispatched_at"`
|
||||
Id int `json:"id"`
|
||||
Message_id string `json:"message_id"`
|
||||
Need_dispatch bool `json:"need_dispatch"`
|
||||
Originator string `json:"originator"`
|
||||
Originator_date_time string `json:"originator_date_time"`
|
||||
Parsed_at time.Time `json:"parsed_at"`
|
||||
Primary_address string `json:"primary_address"`
|
||||
Priority_indicator string `json:"priority_indicator"`
|
||||
Received_at time.Time `json:"received_at"`
|
||||
Secondary_addresses json.RawMessage `json:"secondary_addresses"`
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
Body_and_footer string `json:"body_and_footer"`
|
||||
Body_data string `json:"body_data"`
|
||||
Category string `json:"category"`
|
||||
Date_time string `json:"date_time"`
|
||||
Dispatched_at time.Time `json:"dispatched_at"`
|
||||
Id int `json:"id"`
|
||||
Message_id string `json:"message_id"`
|
||||
Need_dispatch bool `json:"need_dispatch"`
|
||||
Originator string `json:"originator"`
|
||||
Originator_date_time string `json:"originator_date_time"`
|
||||
Parsed_at time.Time `json:"parsed_at"`
|
||||
Primary_address string `json:"primary_address"`
|
||||
Priority_indicator string `json:"priority_indicator"`
|
||||
Received_at time.Time `json:"received_at"`
|
||||
Secondary_addresses string `json:"secondary_addresses"`
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
}
|
||||
|
||||
// GetBody_and_footer returns Aviation_telegrams_insert_input.Body_and_footer, and is useful for accessing the field via an interface.
|
||||
func (v *Aviation_telegrams_insert_input) GetBody_and_footer() string { return v.Body_and_footer }
|
||||
|
||||
// GetBody_data returns Aviation_telegrams_insert_input.Body_data, and is useful for accessing the field via an interface.
|
||||
func (v *Aviation_telegrams_insert_input) GetBody_data() json.RawMessage { return v.Body_data }
|
||||
func (v *Aviation_telegrams_insert_input) GetBody_data() string { return v.Body_data }
|
||||
|
||||
// GetCategory returns Aviation_telegrams_insert_input.Category, and is useful for accessing the field via an interface.
|
||||
func (v *Aviation_telegrams_insert_input) GetCategory() string { return v.Category }
|
||||
@@ -76,7 +75,7 @@ func (v *Aviation_telegrams_insert_input) GetPriority_indicator() string { retur
|
||||
func (v *Aviation_telegrams_insert_input) GetReceived_at() time.Time { return v.Received_at }
|
||||
|
||||
// GetSecondary_addresses returns Aviation_telegrams_insert_input.Secondary_addresses, and is useful for accessing the field via an interface.
|
||||
func (v *Aviation_telegrams_insert_input) GetSecondary_addresses() json.RawMessage {
|
||||
func (v *Aviation_telegrams_insert_input) GetSecondary_addresses() string {
|
||||
return v.Secondary_addresses
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ operations:
|
||||
generated: generated.go
|
||||
bindings:
|
||||
jsonb:
|
||||
type: encoding/json.RawMessage
|
||||
type: string
|
||||
timestamp:
|
||||
type: time.Time
|
||||
uuid:
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
"SuiteHasProgrammaticFocus": false,
|
||||
"SpecialSuiteFailureReasons": null,
|
||||
"PreRunStats": {
|
||||
"TotalSpecs": 3,
|
||||
"TotalSpecs": 1,
|
||||
"SpecsThatWillRun": 1
|
||||
},
|
||||
"StartTime": "2024-07-23T11:25:30.889407931+08:00",
|
||||
"EndTime": "2024-07-23T11:25:30.892377154+08:00",
|
||||
"RunTime": 2969222,
|
||||
"StartTime": "2024-07-23T12:01:15.75278901+08:00",
|
||||
"EndTime": "2024-07-23T12:01:15.764655302+08:00",
|
||||
"RunTime": 11866337,
|
||||
"SuiteConfig": {
|
||||
"RandomSeed": 1721705130,
|
||||
"RandomSeed": 1721707275,
|
||||
"RandomizeAllSpecs": false,
|
||||
"FocusStrings": [
|
||||
"Repositories Hasura Repository should mutate a parsed message"
|
||||
@@ -31,7 +31,7 @@
|
||||
"DryRun": false,
|
||||
"PollProgressAfter": 0,
|
||||
"PollProgressInterval": 0,
|
||||
"Timeout": 3599523895104,
|
||||
"Timeout": 3599595734975,
|
||||
"EmitSpecProgress": false,
|
||||
"OutputInterceptorMode": "",
|
||||
"SourceRoots": null,
|
||||
@@ -41,76 +41,6 @@
|
||||
"ParallelHost": ""
|
||||
},
|
||||
"SpecReports": [
|
||||
{
|
||||
"ContainerHierarchyTexts": [
|
||||
"Repositories",
|
||||
"Just a simple test"
|
||||
],
|
||||
"ContainerHierarchyLocations": [
|
||||
{
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 19
|
||||
},
|
||||
{
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 20
|
||||
}
|
||||
],
|
||||
"ContainerHierarchyLabels": [
|
||||
[],
|
||||
[]
|
||||
],
|
||||
"LeafNodeType": "It",
|
||||
"LeafNodeLocation": {
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 56
|
||||
},
|
||||
"LeafNodeLabels": [],
|
||||
"LeafNodeText": "should not error",
|
||||
"State": "skipped",
|
||||
"StartTime": "2024-07-23T11:25:30.889468443+08:00",
|
||||
"EndTime": "0001-01-01T00:00:00Z",
|
||||
"RunTime": 0,
|
||||
"ParallelProcess": 1,
|
||||
"NumAttempts": 0,
|
||||
"MaxFlakeAttempts": 0,
|
||||
"MaxMustPassRepeatedly": 0
|
||||
},
|
||||
{
|
||||
"ContainerHierarchyTexts": [
|
||||
"Repositories",
|
||||
"Just a simple test"
|
||||
],
|
||||
"ContainerHierarchyLocations": [
|
||||
{
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 19
|
||||
},
|
||||
{
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 20
|
||||
}
|
||||
],
|
||||
"ContainerHierarchyLabels": [
|
||||
[],
|
||||
[]
|
||||
],
|
||||
"LeafNodeType": "It",
|
||||
"LeafNodeLocation": {
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 60
|
||||
},
|
||||
"LeafNodeLabels": [],
|
||||
"LeafNodeText": "name should be new",
|
||||
"State": "skipped",
|
||||
"StartTime": "2024-07-23T11:25:30.889483979+08:00",
|
||||
"EndTime": "0001-01-01T00:00:00Z",
|
||||
"RunTime": 0,
|
||||
"ParallelProcess": 1,
|
||||
"NumAttempts": 0,
|
||||
"MaxFlakeAttempts": 0,
|
||||
"MaxMustPassRepeatedly": 0
|
||||
},
|
||||
{
|
||||
"ContainerHierarchyTexts": [
|
||||
"Repositories",
|
||||
@@ -119,11 +49,11 @@
|
||||
"ContainerHierarchyLocations": [
|
||||
{
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 19
|
||||
"LineNumber": 17
|
||||
},
|
||||
{
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 66
|
||||
"LineNumber": 64
|
||||
}
|
||||
],
|
||||
"ContainerHierarchyLabels": [
|
||||
@@ -133,14 +63,14 @@
|
||||
"LeafNodeType": "It",
|
||||
"LeafNodeLocation": {
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 72
|
||||
"LineNumber": 70
|
||||
},
|
||||
"LeafNodeLabels": [],
|
||||
"LeafNodeText": "should mutate a parsed message",
|
||||
"State": "passed",
|
||||
"StartTime": "2024-07-23T11:25:30.889488379+08:00",
|
||||
"EndTime": "2024-07-23T11:25:30.89235263+08:00",
|
||||
"RunTime": 2864253,
|
||||
"StartTime": "2024-07-23T12:01:15.752849553+08:00",
|
||||
"EndTime": "2024-07-23T12:01:15.764585492+08:00",
|
||||
"RunTime": 11735991,
|
||||
"ParallelProcess": 1,
|
||||
"NumAttempts": 1,
|
||||
"MaxFlakeAttempts": 0,
|
||||
@@ -150,11 +80,11 @@
|
||||
"SpecEventType": "Node",
|
||||
"CodeLocation": {
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 72
|
||||
"LineNumber": 70
|
||||
},
|
||||
"TimelineLocation": {
|
||||
"Order": 1,
|
||||
"Time": "2024-07-23T11:25:30.889491289+08:00"
|
||||
"Time": "2024-07-23T12:01:15.752859429+08:00"
|
||||
},
|
||||
"Message": "should mutate a parsed message",
|
||||
"NodeType": "It"
|
||||
@@ -163,14 +93,14 @@
|
||||
"SpecEventType": "Node (End)",
|
||||
"CodeLocation": {
|
||||
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
|
||||
"LineNumber": 72
|
||||
"LineNumber": 70
|
||||
},
|
||||
"TimelineLocation": {
|
||||
"Order": 3,
|
||||
"Time": "2024-07-23T11:25:30.892349748+08:00"
|
||||
"Time": "2024-07-23T12:01:15.764576564+08:00"
|
||||
},
|
||||
"Message": "should mutate a parsed message",
|
||||
"Duration": 2858459,
|
||||
"Duration": 11717183,
|
||||
"NodeType": "It"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"caatsm/internal/domain"
|
||||
@@ -28,14 +29,15 @@ func NewHasuraRepo(endpoint, secret string) *HasuraRepository {
|
||||
|
||||
// InsertParsedMessage inserts a new ParsedMessage into the Hasura GraphQL API
|
||||
func (hr *HasuraRepository) InsertParsedMessage(pm *domain.ParsedMessage) error {
|
||||
bodyString, _ := json.Marshal(pm.BodyData)
|
||||
variables := Aviation_telegrams_insert_input{
|
||||
// Id: 10,
|
||||
Body_and_footer: pm.BodyAndFooter,
|
||||
// Body_data: pm.BodyData.(json.RawMessage),
|
||||
Category: pm.Category,
|
||||
Date_time: pm.DateTime,
|
||||
Dispatched_at: pm.DispatchedAt,
|
||||
Uuid: uuid.New(),
|
||||
Body_data: string(bodyString),
|
||||
Category: pm.Category,
|
||||
Date_time: pm.DateTime,
|
||||
Dispatched_at: pm.DispatchedAt,
|
||||
Uuid: uuid.New(),
|
||||
}
|
||||
_, err := newMessage(context.Background(), hr.client, variables)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,11 +2,9 @@ package repository
|
||||
|
||||
import (
|
||||
"caatsm/internal/domain"
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hasura/go-graphql-client"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@@ -17,51 +15,51 @@ func TestConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
var _ = Describe("Repositories", func() {
|
||||
Context("Just a simple test", func() {
|
||||
// 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)
|
||||
// // 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
|
||||
}
|
||||
// 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
|
||||
// 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
|
||||
// // 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)
|
||||
// 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())
|
||||
})
|
||||
// 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"))
|
||||
})
|
||||
// It("name should be new", func() {
|
||||
// Expect(mutation.InsertAviationUserOne.Name).To(Equal("new"))
|
||||
// })
|
||||
|
||||
})
|
||||
// })
|
||||
|
||||
Context("Hasura Repository", func() {
|
||||
// var repository *HasuraRepository
|
||||
@@ -82,8 +80,8 @@ var _ = Describe("Repositories", func() {
|
||||
OriginatorDateTime: "originator_date_time",
|
||||
Category: "category",
|
||||
BodyAndFooter: "body_and_footer",
|
||||
// BodyData: &interface{},
|
||||
ReceivedAt: time.Now(),
|
||||
BodyData: domain.ARR{AircraftID: "aircraft_id", Category: "ARR", DepartureAirport: "departure_airport", DepartureTime: "departure_time", ArrivalAirport: "arrival_airport", ArrivalTime: "arrival_time"},
|
||||
ReceivedAt: time.Now(),
|
||||
}
|
||||
err := repository.InsertParsedMessage(parseMessage)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
-1289
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user