Skip to content

Commit

Permalink
Merge pull request #12 from nyaruka/testing
Browse files Browse the repository at this point in the history
Make sure message labels are included in the archives
  • Loading branch information
nicpottier authored May 17, 2018
2 parents 24207cd + 319d7bb commit d988a68
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
16 changes: 14 additions & 2 deletions archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,40 @@ import (
"github.com/sirupsen/logrus"
)

// ArchiveType is the type for the archives
type ArchiveType string

const (
RunType = ArchiveType("run")
// RunType for run archives
RunType = ArchiveType("run")

// MessageType for message archives
MessageType = ArchiveType("message")

// SessionType for session archives
SessionType = ArchiveType("session")
)

// ArchivePeriod is the period of data in the archive
type ArchivePeriod string

const (
Day = ArchivePeriod("D")
// Day id the period of a day (24 hours) from archive start date
Day = ArchivePeriod("D")

// Month is the period of a month from archive start date
Month = ArchivePeriod("M")
)

// Org represents the model for an org
type Org struct {
ID int `db:"id"`
Name string `db:"name"`
CreatedOn time.Time `db:"created_on"`
ActiveDays int
}

// Archive represents the model for an archive
type Archive struct {
ID int `db:"id"`
ArchiveType ArchiveType `db:"archive_type"`
Expand Down
8 changes: 4 additions & 4 deletions archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func TestCreateMsgArchive(t *testing.T) {

// should have two records, second will have attachments
assert.Equal(t, 2, task.RecordCount)
assert.Equal(t, int64(365), task.ArchiveSize)
assert.Equal(t, "cc67ae0d1edb9caa4c8c56b3d4de58ee", task.ArchiveHash)
assert.Equal(t, int64(442), task.ArchiveSize)
assert.Equal(t, "7c39eb3244c34841cf5ca0382519142e", task.ArchiveHash)

DeleteArchiveFile(task)
_, err = os.Stat(task.ArchiveFile)
Expand Down Expand Up @@ -149,6 +149,6 @@ func TestArchiveOrg(t *testing.T) {
assert.Equal(t, "f0d79988b7772c003d04a28bd7417a62", archives[0].ArchiveHash)

assert.Equal(t, 2, archives[2].RecordCount)
assert.Equal(t, int64(365), archives[2].ArchiveSize)
assert.Equal(t, "cc67ae0d1edb9caa4c8c56b3d4de58ee", archives[2].ArchiveHash)
assert.Equal(t, int64(442), archives[2].ArchiveSize)
assert.Equal(t, "7c39eb3244c34841cf5ca0382519142e", archives[2].ArchiveHash)
}
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package archiver

// Config is our top level configuration object
type Config struct {
DB string `help:"the connection string for our database"`
LogLevel string `help:"the log level, one of error, warn, info, debug"`
Expand All @@ -22,6 +23,7 @@ type Config struct {
ArchiveRuns bool `help:"whether we should archive runs"`
}

// NewConfig returns a new default configuration object
func NewConfig() *Config {
config := Config{
DB: "postgres://localhost/temba?sslmode=disable",
Expand Down
13 changes: 12 additions & 1 deletion testdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,15 @@ INSERT INTO contacts_contactgroup_contacts(id, contact_id, contactgroup_id) VALU
INSERT INTO msgs_msg(id, broadcast_id, uuid, text, created_on, sent_on, direction, status, visibility, msg_type, attachments, channel_id, contact_id, contact_urn_id, org_id, msg_count, error_count, next_attempt) VALUES
(1, NULL, '2f969340-704a-4aa2-a1bd-2f832a21d257', 'message 1', '2017-08-12 21:11:59.890662+00', '2017-08-12 21:11:59.890662+00', 'I', 'H', 'V', 'I', NULL, 2, 6, 7, 2, 1, 0, '2017-08-12 21:11:59.890662+00'),
(2, NULL, 'abe87ac1-015c-4803-be29-1e89509fe682', 'message 2', '2017-08-12 21:11:59.890662+00', '2017-08-12 21:11:59.890662+00', 'I', 'H', 'D', 'I', NULL, 2, 6, 7, 2, 1, 0, '2017-08-12 21:11:59.890662+00'),
(3, NULL, 'a7e83a22-a6ff-4e18-82d0-19545640ccba', 'message 3', '2017-08-12 21:11:59.890662+00', '2017-08-12 21:11:59.890662+00', 'O', 'H', 'V', 'I', '{"image/png:https://foo.bar/image1.png", "image/png:https://foo.bar/image2.png"}', 2, 6, 7, 2, 1, 0, '2017-08-12 21:11:59.890662+00');
(3, NULL, 'a7e83a22-a6ff-4e18-82d0-19545640ccba', 'message 3', '2017-08-12 21:11:59.890662+00', '2017-08-12 21:11:59.890662+00', 'O', 'H', 'V', 'I', '{"image/png:https://foo.bar/image1.png", "image/png:https://foo.bar/image2.png"}', 2, 6, 7, 2, 1, 0, '2017-08-12 21:11:59.890662+00');

INSERT INTO msgs_label(id, uuid, name) VALUES
(1, '1d9e3188-b74b-4ae0-a166-0de31aedb34a', 'Label 1'),
(2, 'c5a69101-8dc3-444f-8b0b-5ab816e46eec', 'Label 2'),
(3, '9e13d3b6-1ffa-406e-b66b-5cebe6738488', 'Label 3');

INSERT INTO msgs_msg_labels(id, msg_id, label_id) VALUES
(1, 1, 1),
(2, 1, 2),
(3, 2, 2),
(4, 3, 2);

0 comments on commit d988a68

Please sign in to comment.