Skip to content

Commit

Permalink
[BSA-3322] Add last_seen_at to users data feed (#170)
Browse files Browse the repository at this point in the history
Adds `last_seen_at` to the users data feed.
  • Loading branch information
BCook98 authored Oct 20, 2021
1 parent 9dfd260 commit 6b1d30f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 28 deletions.
18 changes: 9 additions & 9 deletions internal/app/feed/exporter_csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,[email protected],User 1,User 1,false,--date--
user_2,role_123,[email protected],User 2,User 2,false,--date--
user_3,role_123,[email protected],User 3,User 3,false,--date--`
expected := `user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at
user_1,role_123,[email protected],User 1,User 1,false,,--date--
user_2,role_123,[email protected],User 2,User 2,false,,--date--
user_3,role_123,[email protected],User 3,User 3,false,,--date--`
assert.Equal(t, strings.TrimSpace(expected), contentString)
}

Expand Down Expand Up @@ -475,17 +475,17 @@ 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,[email protected],User 1,User 1,false,--date--
user_2,role_123,[email protected],User 2,User 2,false,--date--`
expected1 := `user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at
user_1,role_123,[email protected],User 1,User 1,false,,--date--
user_2,role_123,[email protected],User 2,User 2,false,,--date--`
assert.Equal(t, strings.TrimSpace(expected1), content1String)

content2, err := ioutil.ReadFile(files[1])
assert.Nil(t, err)

content2String := dateRegex.ReplaceAllLiteralString(strings.TrimSpace(string(content2)), "--date--")

expected2 := `user_id,organisation_id,email,firstname,lastname,active,exported_at
user_3,role_123,[email protected],User 3,User 3,false,--date--`
expected2 := `user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at
user_3,role_123,[email protected],User 3,User 3,false,,--date--`
assert.Equal(t, strings.TrimSpace(expected2), content2String)
}
16 changes: 9 additions & 7 deletions internal/app/feed/feed_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,6 +52,7 @@ func (f *UserFeed) Columns() []string {
"firstname",
"lastname",
"active",
"last_seen_at",
"exported_at",
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/app/feed/mocks/set_1/feed_users_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions internal/app/feed/mocks/set_1/outputs/users.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
user_id,organisation_id,email,firstname,lastname,active,exported_at
user_1,role_123,[email protected],Dwight,Schrute,true,--date--
user_2,role_123,[email protected],Abraham,Lincoln,true,--date--
user_3,role_123,[email protected],Stefani Joanne Angelina,Germanotta,true,--date--
user_4,role_123,tests+Agnetha.Fä[email protected],Agnetha,Fältskog,false,--date--
user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at
user_1,role_123,[email protected],Dwight,Schrute,true,--date--,--date--
user_2,role_123,[email protected],Abraham,Lincoln,true,,--date--
user_3,role_123,[email protected],Stefani Joanne Angelina,Germanotta,true,,--date--
user_4,role_123,tests+Agnetha.Fä[email protected],Agnetha,Fältskog,false,,--date--
1 change: 1 addition & 0 deletions internal/app/feed/mocks/set_1/schemas/formatted/users.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
| firstname | text | |
| lastname | text | |
| active | numeric | |
| last_seen_at | datetime | |
| exported_at | datetime | |
+-----------------+----------+-------------+
2 changes: 1 addition & 1 deletion internal/app/feed/mocks/set_1/schemas/users.csv
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions internal/app/feed/mocks/set_2/outputs/users.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
user_id,organisation_id,email,firstname,lastname,active,exported_at
user_1,role_123,[email protected],Dwight,Schrute,true,--date--
user_2,role_123,[email protected],Abraham,Lincoln,true,--date--
user_3,role_123,[email protected],Stefani Joanne Angelina,Germanotta,true,--date--
user_4,role_123,tests+Agnetha.Fä[email protected],Agnetha,Fältskog,false,--date--
user_id,organisation_id,email,firstname,lastname,active,last_seen_at,exported_at
user_1,role_123,[email protected],Dwight,Schrute,true,--date--,--date--
user_2,role_123,[email protected],Abraham,Lincoln,true,,--date--
user_3,role_123,[email protected],Stefani Joanne Angelina,Germanotta,true,,--date--
user_4,role_123,tests+Agnetha.Fä[email protected],Agnetha,Fältskog,false,,--date--

0 comments on commit 6b1d30f

Please sign in to comment.