Skip to content

Commit

Permalink
Drop db support on flows.BroadcastTranslations
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jun 26, 2024
1 parent e2f0b22 commit 37040c1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 23 deletions.
14 changes: 0 additions & 14 deletions flows/msg.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package flows

import (
"database/sql/driver"
"encoding/json"
"errors"
"fmt"
"slices"

Expand Down Expand Up @@ -220,14 +217,3 @@ func (b BroadcastTranslations) ForContact(e envs.Environment, c *Contact, baseLa
// finally return the base language
return b[baseLanguage], baseLanguage
}

// Scan supports reading translation values from JSON in database
func (t *BroadcastTranslations) Scan(value any) error {
b, ok := value.([]byte)
if !ok {
return errors.New("failed type assertion to []byte")
}
return json.Unmarshal(b, &t)
}

func (t BroadcastTranslations) Value() (driver.Value, error) { return json.Marshal(t) }
9 changes: 0 additions & 9 deletions flows/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,6 @@ func TestBroadcastTranslations(t *testing.T) {
assertTranslation("kin", []i18n.Language{"eng", "spa"}, "Hello", "eng") // uses default flow language
assertTranslation("kin", []i18n.Language{"spa", "eng"}, "Hola", "spa") // uses default flow language
assertTranslation("kin", []i18n.Language{"kin"}, "Hello", "eng") // uses base language

val, err := bcastTrans.Value()
assert.NoError(t, err)
assert.JSONEq(t, `{"eng": {"text": "Hello"}, "fra": {"text": "Bonjour"}, "spa": {"text": "Hola"}}`, string(val.([]byte)))

var bt flows.BroadcastTranslations
err = bt.Scan([]byte(`{"spa": {"text": "Adios"}}`))
assert.NoError(t, err)
assert.Equal(t, flows.BroadcastTranslations{"spa": {Text: "Adios"}}, bt)
}

func TestMsgTemplating(t *testing.T) {
Expand Down

0 comments on commit 37040c1

Please sign in to comment.