From 6b1d30f4877e849af2e19f878d43cc6aeaedd4d5 Mon Sep 17 00:00:00 2001 From: Brandon Cook Date: Wed, 20 Oct 2021 17:05:57 +1300 Subject: [PATCH] [BSA-3322] Add last_seen_at to users data feed (#170) Adds `last_seen_at` to the users data feed. --- internal/app/feed/exporter_csv_test.go | 18 +++++++++--------- internal/app/feed/feed_user.go | 16 +++++++++------- .../app/feed/mocks/set_1/feed_users_1.json | 3 ++- .../app/feed/mocks/set_1/outputs/users.csv | 10 +++++----- .../mocks/set_1/schemas/formatted/users.txt | 1 + .../app/feed/mocks/set_1/schemas/users.csv | 2 +- .../app/feed/mocks/set_2/outputs/users.csv | 10 +++++----- 7 files changed, 32 insertions(+), 28 deletions(-) diff --git a/internal/app/feed/exporter_csv_test.go b/internal/app/feed/exporter_csv_test.go index 9848270c..947632fe 100644 --- a/internal/app/feed/exporter_csv_test.go +++ b/internal/app/feed/exporter_csv_test.go @@ -418,10 +418,10 @@ func TestCSVExporterFinaliseExport_should_write_rows_out_to_file(t *testing.T) { contentString := dateRegex.ReplaceAllLiteralString(strings.TrimSpace(string(content)), "--date--") - expected := `user_id,organisation_id,email,firstname,lastname,active,exported_at -user_1,role_123,user.1@test.com,User 1,User 1,false,--date-- -user_2,role_123,user.2@test.com,User 2,User 2,false,--date-- -user_3,role_123,user.3@test.com,User 3,User 3,false,--date--` + expected := `user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at +user_1,role_123,user.1@test.com,User 1,User 1,false,,--date-- +user_2,role_123,user.2@test.com,User 2,User 2,false,,--date-- +user_3,role_123,user.3@test.com,User 3,User 3,false,,--date--` assert.Equal(t, strings.TrimSpace(expected), contentString) } @@ -475,9 +475,9 @@ func TestCSVExporterFinaliseExport_should_write_rows_to_multiple_file(t *testing content1String := dateRegex.ReplaceAllLiteralString(strings.TrimSpace(string(content1)), "--date--") - expected1 := `user_id,organisation_id,email,firstname,lastname,active,exported_at -user_1,role_123,user.1@test.com,User 1,User 1,false,--date-- -user_2,role_123,user.2@test.com,User 2,User 2,false,--date--` + expected1 := `user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at +user_1,role_123,user.1@test.com,User 1,User 1,false,,--date-- +user_2,role_123,user.2@test.com,User 2,User 2,false,,--date--` assert.Equal(t, strings.TrimSpace(expected1), content1String) content2, err := ioutil.ReadFile(files[1]) @@ -485,7 +485,7 @@ user_2,role_123,user.2@test.com,User 2,User 2,false,--date--` content2String := dateRegex.ReplaceAllLiteralString(strings.TrimSpace(string(content2)), "--date--") - expected2 := `user_id,organisation_id,email,firstname,lastname,active,exported_at -user_3,role_123,user.3@test.com,User 3,User 3,false,--date--` + expected2 := `user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at +user_3,role_123,user.3@test.com,User 3,User 3,false,,--date--` assert.Equal(t, strings.TrimSpace(expected2), content2String) } diff --git a/internal/app/feed/feed_user.go b/internal/app/feed/feed_user.go index e4f42b5a..a2708bac 100644 --- a/internal/app/feed/feed_user.go +++ b/internal/app/feed/feed_user.go @@ -11,13 +11,14 @@ import ( // User represents a row from the users feed type User struct { - ID string `json:"id" csv:"user_id" gorm:"primarykey;column:user_id;size:37"` - OrganisationID string `json:"organisation_id" csv:"organisation_id" gorm:"size:37"` - Email string `json:"email" csv:"email" gorm:"size:256"` - Firstname string `json:"firstname" csv:"firstname"` - Lastname string `json:"lastname" csv:"lastname"` - Active bool `json:"active" csv:"active"` - ExportedAt time.Time `json:"exported_at" csv:"exported_at" gorm:"autoUpdateTime"` + ID string `json:"id" csv:"user_id" gorm:"primarykey;column:user_id;size:37"` + OrganisationID string `json:"organisation_id" csv:"organisation_id" gorm:"size:37"` + Email string `json:"email" csv:"email" gorm:"size:256"` + Firstname string `json:"firstname" csv:"firstname"` + Lastname string `json:"lastname" csv:"lastname"` + Active bool `json:"active" csv:"active"` + LastSeenAt *time.Time `json:"last_seen_at" csv:"last_seen_at"` + ExportedAt time.Time `json:"exported_at" csv:"exported_at" gorm:"autoUpdateTime"` } // UserFeed is a representation of the users feed @@ -51,6 +52,7 @@ func (f *UserFeed) Columns() []string { "firstname", "lastname", "active", + "last_seen_at", "exported_at", } } diff --git a/internal/app/feed/mocks/set_1/feed_users_1.json b/internal/app/feed/mocks/set_1/feed_users_1.json index e74dd0c6..9473a165 100644 --- a/internal/app/feed/mocks/set_1/feed_users_1.json +++ b/internal/app/feed/mocks/set_1/feed_users_1.json @@ -11,7 +11,8 @@ "firstname": "Dwight", "lastname": "Schrute", "active": true, - "organisation_id": "role_123" + "organisation_id": "role_123", + "last_seen_at": "2020-10-29T12:28:42.000Z" }, { "id": "user_2", diff --git a/internal/app/feed/mocks/set_1/outputs/users.csv b/internal/app/feed/mocks/set_1/outputs/users.csv index 956081a8..c5e2030e 100644 --- a/internal/app/feed/mocks/set_1/outputs/users.csv +++ b/internal/app/feed/mocks/set_1/outputs/users.csv @@ -1,5 +1,5 @@ -user_id,organisation_id,email,firstname,lastname,active,exported_at -user_1,role_123,tests+dwight.schrute@safetyculture.io,Dwight,Schrute,true,--date-- -user_2,role_123,tests+abraham.lincoln@safetyculture.io,Abraham,Lincoln,true,--date-- -user_3,role_123,tests+stefani.joanne.angelina.germanotta@safetyculture.io,Stefani Joanne Angelina,Germanotta,true,--date-- -user_4,role_123,tests+Agnetha.Fältskog@safetyculture.io,Agnetha,Fältskog,false,--date-- +user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at +user_1,role_123,tests+dwight.schrute@safetyculture.io,Dwight,Schrute,true,--date--,--date-- +user_2,role_123,tests+abraham.lincoln@safetyculture.io,Abraham,Lincoln,true,,--date-- +user_3,role_123,tests+stefani.joanne.angelina.germanotta@safetyculture.io,Stefani Joanne Angelina,Germanotta,true,,--date-- +user_4,role_123,tests+Agnetha.Fältskog@safetyculture.io,Agnetha,Fältskog,false,,--date-- diff --git a/internal/app/feed/mocks/set_1/schemas/formatted/users.txt b/internal/app/feed/mocks/set_1/schemas/formatted/users.txt index 47f5d96e..6c67aa1d 100644 --- a/internal/app/feed/mocks/set_1/schemas/formatted/users.txt +++ b/internal/app/feed/mocks/set_1/schemas/formatted/users.txt @@ -7,5 +7,6 @@ | firstname | text | | | lastname | text | | | active | numeric | | +| last_seen_at | datetime | | | exported_at | datetime | | +-----------------+----------+-------------+ diff --git a/internal/app/feed/mocks/set_1/schemas/users.csv b/internal/app/feed/mocks/set_1/schemas/users.csv index ebf43c08..07395108 100644 --- a/internal/app/feed/mocks/set_1/schemas/users.csv +++ b/internal/app/feed/mocks/set_1/schemas/users.csv @@ -1 +1 @@ -user_id,organisation_id,email,firstname,lastname,active,exported_at +user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at diff --git a/internal/app/feed/mocks/set_2/outputs/users.csv b/internal/app/feed/mocks/set_2/outputs/users.csv index 956081a8..c5e2030e 100644 --- a/internal/app/feed/mocks/set_2/outputs/users.csv +++ b/internal/app/feed/mocks/set_2/outputs/users.csv @@ -1,5 +1,5 @@ -user_id,organisation_id,email,firstname,lastname,active,exported_at -user_1,role_123,tests+dwight.schrute@safetyculture.io,Dwight,Schrute,true,--date-- -user_2,role_123,tests+abraham.lincoln@safetyculture.io,Abraham,Lincoln,true,--date-- -user_3,role_123,tests+stefani.joanne.angelina.germanotta@safetyculture.io,Stefani Joanne Angelina,Germanotta,true,--date-- -user_4,role_123,tests+Agnetha.Fältskog@safetyculture.io,Agnetha,Fältskog,false,--date-- +user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at +user_1,role_123,tests+dwight.schrute@safetyculture.io,Dwight,Schrute,true,--date--,--date-- +user_2,role_123,tests+abraham.lincoln@safetyculture.io,Abraham,Lincoln,true,,--date-- +user_3,role_123,tests+stefani.joanne.angelina.germanotta@safetyculture.io,Stefani Joanne Angelina,Germanotta,true,,--date-- +user_4,role_123,tests+Agnetha.Fältskog@safetyculture.io,Agnetha,Fältskog,false,,--date--