diff --git a/flows/actions/testdata/transfer_airtime.json b/flows/actions/testdata/transfer_airtime.json index 2c74b89b2..107ff53cb 100644 --- a/flows/actions/testdata/transfer_airtime.json +++ b/flows/actions/testdata/transfer_airtime.json @@ -194,6 +194,7 @@ "events": [ { "type": "airtime_transferred", + "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", "created_on": "2018-10-18T14:20:30.000123456Z", "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "sender": "tel:+17036975131", @@ -292,6 +293,7 @@ "events": [ { "type": "airtime_transferred", + "uuid": "9688d21d-95aa-4bed-afc7-f31b35731a3d", "created_on": "2018-10-18T14:20:30.000123456Z", "step_uuid": "59d74b86-3e2f-4a93-aece-b05d2fdcde0c", "sender": "tel:+17036975131", diff --git a/flows/events/airtime_transferred.go b/flows/events/airtime_transferred.go index ebecc2dca..8e2d54bbf 100644 --- a/flows/events/airtime_transferred.go +++ b/flows/events/airtime_transferred.go @@ -19,6 +19,7 @@ const TypeAirtimeTransferred string = "airtime_transferred" // { // "type": "airtime_transferred", // "created_on": "2006-01-02T15:04:05Z", +// "uuid": "552cd7ee-ccba-404d-9692-c1fe3b8d57c5", // "sender": "tel:4748", // "recipient": "tel:+1242563637", // "currency": "RWF", @@ -40,18 +41,20 @@ const TypeAirtimeTransferred string = "airtime_transferred" type AirtimeTransferredEvent struct { BaseEvent - Sender urns.URN `json:"sender"` - Recipient urns.URN `json:"recipient"` - Currency string `json:"currency"` - DesiredAmount decimal.Decimal `json:"desired_amount"` - ActualAmount decimal.Decimal `json:"actual_amount"` - HTTPLogs []*flows.HTTPLog `json:"http_logs"` + UUID flows.AirtimeTransferUUID `json:"uuid"` + Sender urns.URN `json:"sender"` + Recipient urns.URN `json:"recipient"` + Currency string `json:"currency"` + DesiredAmount decimal.Decimal `json:"desired_amount"` + ActualAmount decimal.Decimal `json:"actual_amount"` + HTTPLogs []*flows.HTTPLog `json:"http_logs"` } // NewAirtimeTransferred creates a new airtime transferred event func NewAirtimeTransferred(t *flows.AirtimeTransfer, httpLogs []*flows.HTTPLog) *AirtimeTransferredEvent { return &AirtimeTransferredEvent{ BaseEvent: NewBaseEvent(TypeAirtimeTransferred), + UUID: t.UUID, Sender: t.Sender, Recipient: t.Recipient, Currency: t.Currency, diff --git a/flows/events/base_test.go b/flows/events/base_test.go index 90159fe97..5d462ee4f 100644 --- a/flows/events/base_test.go +++ b/flows/events/base_test.go @@ -57,6 +57,7 @@ func TestEventMarshaling(t *testing.T) { { events.NewAirtimeTransferred( &flows.AirtimeTransfer{ + UUID: flows.AirtimeTransferUUID("4c2d9b7a-e02c-4e6a-ab18-06df4cb5666d"), Sender: urns.URN("tel:+593979099111"), Recipient: urns.URN("tel:+593979099222"), Currency: "USD", @@ -98,7 +99,8 @@ func TestEventMarshaling(t *testing.T) { ], "recipient": "tel:+593979099222", "sender": "tel:+593979099111", - "type": "airtime_transferred" + "type": "airtime_transferred", + "uuid": "4c2d9b7a-e02c-4e6a-ab18-06df4cb5666d" }`, }, { diff --git a/flows/services.go b/flows/services.go index 02321fa40..07159f8e4 100644 --- a/flows/services.go +++ b/flows/services.go @@ -143,6 +143,9 @@ type TicketService interface { Open(env envs.Environment, contact *Contact, topic *Topic, body string, assignee *User, logHTTP HTTPLogCallback) (*Ticket, error) } +// AirtimeTransferUUID is the UUID of a airtime transfer +type AirtimeTransferUUID uuids.UUID + // AirtimeTransferStatus is a status of a airtime transfer type AirtimeTransferStatus string @@ -154,7 +157,7 @@ const ( // AirtimeTransfer is the result of an attempted airtime transfer type AirtimeTransfer struct { - UUID uuids.UUID + UUID AirtimeTransferUUID Sender urns.URN Recipient urns.URN Currency string diff --git a/services/airtime/dtone/service.go b/services/airtime/dtone/service.go index 805363f8e..c1399d4ae 100644 --- a/services/airtime/dtone/service.go +++ b/services/airtime/dtone/service.go @@ -28,9 +28,10 @@ func NewService(httpClient *http.Client, httpRetries *httpx.RetryConfig, key, se func (s *service) Transfer(sender urns.URN, recipient urns.URN, amounts map[string]decimal.Decimal, logHTTP flows.HTTPLogCallback) (*flows.AirtimeTransfer, error) { transfer := &flows.AirtimeTransfer{ - UUID: uuids.New(), + UUID: flows.AirtimeTransferUUID(uuids.New()), Sender: sender, Recipient: recipient, + Currency: "", DesiredAmount: decimal.Zero, ActualAmount: decimal.Zero, } diff --git a/services/airtime/dtone/service_test.go b/services/airtime/dtone/service_test.go index d0744d604..5da2a4f48 100644 --- a/services/airtime/dtone/service_test.go +++ b/services/airtime/dtone/service_test.go @@ -58,7 +58,7 @@ func TestServiceWithSuccessfulTranfer(t *testing.T) { ) assert.NoError(t, err) assert.Equal(t, &flows.AirtimeTransfer{ - UUID: uuids.UUID("1ae96956-4b34-433e-8d1a-f05fe6923d6d"), + UUID: flows.AirtimeTransferUUID("1ae96956-4b34-433e-8d1a-f05fe6923d6d"), Sender: urns.URN("tel:+593979000000"), Recipient: urns.URN("tel:+593979123456"), Currency: "USD", diff --git a/test/engine.go b/test/engine.go index 02d4b01e5..4ba2b5987 100644 --- a/test/engine.go +++ b/test/engine.go @@ -7,6 +7,7 @@ import ( "github.com/nyaruka/gocommon/httpx" "github.com/nyaruka/gocommon/urns" + "github.com/nyaruka/gocommon/uuids" "github.com/nyaruka/goflow/envs" "github.com/nyaruka/goflow/flows" "github.com/nyaruka/goflow/flows/engine" @@ -120,6 +121,7 @@ func (s *airtimeService) Transfer(sender urns.URN, recipient urns.URN, amounts m } transfer := &flows.AirtimeTransfer{ + UUID: flows.AirtimeTransferUUID(uuids.New()), Sender: sender, Recipient: recipient, Currency: s.fixedCurrency, diff --git a/test/testdata/runner/airtime.test_successful_transfer.json b/test/testdata/runner/airtime.test_successful_transfer.json index cb8e24943..05c4dab06 100644 --- a/test/testdata/runner/airtime.test_successful_transfer.json +++ b/test/testdata/runner/airtime.test_successful_transfer.json @@ -167,7 +167,8 @@ "recipient": "tel:+12065551212", "sender": "", "step_uuid": "8720f157-ca1c-432f-9c0b-2014ddc77094", - "type": "airtime_transferred" + "type": "airtime_transferred", + "uuid": "c34b6c7d-fa06-4563-92a3-d648ab64bccb" }, { "category": "Success", @@ -251,7 +252,8 @@ "recipient": "tel:+12065551212", "sender": "", "step_uuid": "8720f157-ca1c-432f-9c0b-2014ddc77094", - "type": "airtime_transferred" + "type": "airtime_transferred", + "uuid": "c34b6c7d-fa06-4563-92a3-d648ab64bccb" }, { "category": "Success",