@@ -25,6 +25,11 @@ import (
2525 "github.com/bucketeer-io/bucketeer/v2/proto/common"
2626)
2727
28+ func backdateUpdatedAt (a * AccountV2 ) int64 {
29+ a .UpdatedAt = time .Now ().Add (- time .Hour ).Unix ()
30+ return a .UpdatedAt
31+ }
32+
2833func TestNewMemberAccount (t * testing.T ) {
2934 envRoles := []* proto.AccountV2_EnvironmentRole {
3035 {
@@ -460,6 +465,7 @@ func TestAddSearchFilter(t *testing.T) {
460465 []string {"team" },
461466 account .OrganizationId ,
462467 account .OrganizationRole , account .EnvironmentRoles )
468+ backdatedUpdatedAt := backdateUpdatedAt (a )
463469 for _ , f := range p .expectedFilters {
464470 _ , err := a .AddSearchFilter (f .Name , f .Query , f .FilterTargetType , f .EnvironmentId , f .DefaultFilter )
465471 assert .Nil (t , err )
@@ -474,7 +480,11 @@ func TestAddSearchFilter(t *testing.T) {
474480 assert .Equal (t , account .OrganizationId , a .OrganizationId )
475481 assert .Equal (t , account .OrganizationRole , a .OrganizationRole )
476482 assert .Equal (t , account .EnvironmentRoles , a .EnvironmentRoles )
477- assert .InDelta (t , time .Now ().Unix (), a .UpdatedAt , 5 )
483+ if len (p .expectedFilters ) > 0 {
484+ assert .InDelta (t , time .Now ().Unix (), a .UpdatedAt , 5 )
485+ } else {
486+ assert .Equal (t , backdatedUpdatedAt , a .UpdatedAt )
487+ }
478488
479489 assert .Equal (t , len (p .expectedFilters ), len (a .SearchFilters ))
480490 for i , f := range p .expectedFilters {
@@ -627,6 +637,7 @@ func TestChangeSearchFilterName(t *testing.T) {
627637 if len (a .SearchFilters ) > 0 {
628638 updateFilterId = a .SearchFilters [(len (a .SearchFilters ) / 2 )].Id
629639 }
640+ backdatedUpdatedAt := backdateUpdatedAt (a )
630641 err := a .ChangeSearchFilterName (updateFilterId , p .updateFilterName )
631642 assert .Equal (t , err , p .error )
632643
@@ -640,7 +651,11 @@ func TestChangeSearchFilterName(t *testing.T) {
640651 assert .Equal (t , account .OrganizationId , a .OrganizationId )
641652 assert .Equal (t , account .OrganizationRole , a .OrganizationRole )
642653 assert .Equal (t , account .EnvironmentRoles , a .EnvironmentRoles )
643- assert .InDelta (t , time .Now ().Unix (), a .UpdatedAt , 5 )
654+ if p .error == nil {
655+ assert .InDelta (t , time .Now ().Unix (), a .UpdatedAt , 5 )
656+ } else {
657+ assert .Equal (t , backdatedUpdatedAt , a .UpdatedAt )
658+ }
644659
645660 assert .Equal (t , len (p .expectedFilters ), len (a .SearchFilters ))
646661 for i , f := range p .expectedFilters {
@@ -781,6 +796,7 @@ func TestChangeSearchFilterQuery(t *testing.T) {
781796 if len (a .SearchFilters ) > 0 {
782797 updateFilterId = a .SearchFilters [(len (a .SearchFilters ) / 2 )].Id
783798 }
799+ backdatedUpdatedAt := backdateUpdatedAt (a )
784800 err := a .ChangeSearchFilterQuery (updateFilterId , p .updateFilterQuery )
785801 assert .Equal (t , err , p .error )
786802
@@ -794,7 +810,11 @@ func TestChangeSearchFilterQuery(t *testing.T) {
794810 assert .Equal (t , account .OrganizationId , a .OrganizationId )
795811 assert .Equal (t , account .OrganizationRole , a .OrganizationRole )
796812 assert .Equal (t , account .EnvironmentRoles , a .EnvironmentRoles )
797- assert .InDelta (t , time .Now ().Unix (), a .UpdatedAt , 5 )
813+ if p .error == nil {
814+ assert .InDelta (t , time .Now ().Unix (), a .UpdatedAt , 5 )
815+ } else {
816+ assert .Equal (t , backdatedUpdatedAt , a .UpdatedAt )
817+ }
798818
799819 assert .Equal (t , len (p .expectedFilters ), len (a .SearchFilters ))
800820 for i , f := range p .expectedFilters {
@@ -939,6 +959,7 @@ func TestChangeDefaultSearchFilter(t *testing.T) {
939959 Id : updateFilterId ,
940960 DefaultFilter : p .updateDefaultFilter ,
941961 }
962+ backdatedUpdatedAt := backdateUpdatedAt (a )
942963 err := a .ChangeDefaultSearchFilter (
943964 updateFilter .Id ,
944965 updateFilter .DefaultFilter )
@@ -954,7 +975,11 @@ func TestChangeDefaultSearchFilter(t *testing.T) {
954975 assert .Equal (t , account .OrganizationId , a .OrganizationId )
955976 assert .Equal (t , account .OrganizationRole , a .OrganizationRole )
956977 assert .Equal (t , account .EnvironmentRoles , a .EnvironmentRoles )
957- assert .InDelta (t , time .Now ().Unix (), a .UpdatedAt , 5 )
978+ if p .error == nil {
979+ assert .InDelta (t , time .Now ().Unix (), a .UpdatedAt , 5 )
980+ } else {
981+ assert .Equal (t , backdatedUpdatedAt , a .UpdatedAt )
982+ }
958983
959984 assert .Equal (t , len (p .expectedFilters ), len (a .SearchFilters ))
960985 for i , f := range p .expectedFilters {
@@ -1076,6 +1101,7 @@ func TestDeleteSearchFilter(t *testing.T) {
10761101 if len (a .SearchFilters ) > 0 {
10771102 deleteFilterId = a .SearchFilters [(len (a .SearchFilters ) / 2 )].Id
10781103 }
1104+ backdatedUpdatedAt := backdateUpdatedAt (a )
10791105 err := a .DeleteSearchFilter (deleteFilterId )
10801106 assert .Equal (t , err , p .error )
10811107
@@ -1089,7 +1115,11 @@ func TestDeleteSearchFilter(t *testing.T) {
10891115 assert .Equal (t , account .OrganizationId , a .OrganizationId )
10901116 assert .Equal (t , account .OrganizationRole , a .OrganizationRole )
10911117 assert .Equal (t , account .EnvironmentRoles , a .EnvironmentRoles )
1092- assert .InDelta (t , time .Now ().Unix (), a .UpdatedAt , 5 )
1118+ if p .error == nil {
1119+ assert .InDelta (t , time .Now ().Unix (), a .UpdatedAt , 5 )
1120+ } else {
1121+ assert .Equal (t , backdatedUpdatedAt , a .UpdatedAt )
1122+ }
10931123
10941124 assert .Equal (t , len (p .expectedFilters ), len (a .SearchFilters ))
10951125 if len (a .SearchFilters ) > 0 {
0 commit comments