refactor: tests - delete unnecessary nestings
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
99158e3410
commit
ac6330a3b1
|
@ -136,162 +136,158 @@ func TestGroup_Create(t *testing.T) {
|
||||||
func TestGroup_CleanUp(t *testing.T) {
|
func TestGroup_CleanUp(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
t.Run("OK", func(t *testing.T) {
|
repo := &mock.FakeGroupRepository{}
|
||||||
t.Parallel()
|
groupsWithDisabledNotifications := []domain.Group{
|
||||||
|
{
|
||||||
|
ID: uuid.NewString(),
|
||||||
|
ServerID: uuid.NewString(),
|
||||||
|
ChannelGains: "",
|
||||||
|
ChannelLosses: "",
|
||||||
|
Internals: true,
|
||||||
|
Barbarians: true,
|
||||||
|
ServerKey: "pl181",
|
||||||
|
VersionCode: "pl",
|
||||||
|
CreatedAt: time.Now().Add(-48 * time.Hour),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: uuid.NewString(),
|
||||||
|
ServerID: uuid.NewString(),
|
||||||
|
ChannelGains: "",
|
||||||
|
ChannelLosses: "",
|
||||||
|
Internals: true,
|
||||||
|
Barbarians: true,
|
||||||
|
ServerKey: "pl181",
|
||||||
|
VersionCode: "pl",
|
||||||
|
CreatedAt: time.Now().Add(-45 * time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
repo.ListReturnsOnCall(0, groupsWithDisabledNotifications, nil)
|
||||||
|
groupsPL := []domain.Group{
|
||||||
|
{
|
||||||
|
ID: uuid.NewString(),
|
||||||
|
ServerID: uuid.NewString(),
|
||||||
|
ChannelGains: uuid.NewString(),
|
||||||
|
ChannelLosses: "",
|
||||||
|
Internals: true,
|
||||||
|
Barbarians: true,
|
||||||
|
ServerKey: "pl181",
|
||||||
|
VersionCode: "pl",
|
||||||
|
CreatedAt: time.Now().Add(-120 * time.Hour),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: uuid.NewString(),
|
||||||
|
ServerID: uuid.NewString(),
|
||||||
|
ChannelGains: uuid.NewString(),
|
||||||
|
ChannelLosses: uuid.NewString(),
|
||||||
|
Internals: true,
|
||||||
|
Barbarians: true,
|
||||||
|
ServerKey: "pl181",
|
||||||
|
VersionCode: "pl",
|
||||||
|
CreatedAt: time.Now().Add(-11 * time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
repo.ListReturnsOnCall(1, groupsPL, nil)
|
||||||
|
groupsUK := []domain.Group{
|
||||||
|
{
|
||||||
|
ID: uuid.NewString(),
|
||||||
|
ServerID: uuid.NewString(),
|
||||||
|
ChannelGains: uuid.NewString(),
|
||||||
|
ChannelLosses: uuid.NewString(),
|
||||||
|
Internals: true,
|
||||||
|
Barbarians: true,
|
||||||
|
ServerKey: "uk51",
|
||||||
|
VersionCode: "uk",
|
||||||
|
CreatedAt: time.Now().Add(-150 * time.Hour),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: uuid.NewString(),
|
||||||
|
ServerID: uuid.NewString(),
|
||||||
|
ChannelGains: uuid.NewString(),
|
||||||
|
ChannelLosses: uuid.NewString(),
|
||||||
|
Internals: true,
|
||||||
|
Barbarians: true,
|
||||||
|
ServerKey: "uk52",
|
||||||
|
VersionCode: "uk",
|
||||||
|
CreatedAt: time.Now().Add(-200 * time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
repo.ListReturnsOnCall(2, groupsUK, nil)
|
||||||
|
repo.DeleteManyReturns(nil)
|
||||||
|
|
||||||
repo := &mock.FakeGroupRepository{}
|
client := &mock.FakeTWHelpClient{}
|
||||||
groupsWithDisabledNotifications := []domain.Group{
|
versions := []twhelp.Version{
|
||||||
{
|
{
|
||||||
ID: uuid.NewString(),
|
Code: "pl",
|
||||||
ServerID: uuid.NewString(),
|
Host: "www.plemiona.pl",
|
||||||
ChannelGains: "",
|
Name: "Poland",
|
||||||
ChannelLosses: "",
|
Timezone: "Europe/Warsaw",
|
||||||
Internals: true,
|
},
|
||||||
Barbarians: true,
|
{
|
||||||
ServerKey: "pl181",
|
Code: "uk",
|
||||||
VersionCode: "pl",
|
Host: "www.tribalwars.co.uk",
|
||||||
CreatedAt: time.Now().Add(-48 * time.Hour),
|
Name: "United Kingdom",
|
||||||
},
|
Timezone: "Europe/London",
|
||||||
{
|
},
|
||||||
ID: uuid.NewString(),
|
{
|
||||||
ServerID: uuid.NewString(),
|
Code: "tr",
|
||||||
ChannelGains: "",
|
Host: "www.klanlar.org",
|
||||||
ChannelLosses: "",
|
Name: "Turkey",
|
||||||
Internals: true,
|
Timezone: "Europe/Istanbul",
|
||||||
Barbarians: true,
|
},
|
||||||
ServerKey: "pl181",
|
}
|
||||||
VersionCode: "pl",
|
client.ListVersionsReturns(versions, nil)
|
||||||
CreatedAt: time.Now().Add(-45 * time.Hour),
|
serversPL := []twhelp.Server{
|
||||||
},
|
{
|
||||||
}
|
Key: "pl181",
|
||||||
repo.ListReturnsOnCall(0, groupsWithDisabledNotifications, nil)
|
URL: "https://pl181.plemiona.pl",
|
||||||
groupsPL := []domain.Group{
|
Open: false,
|
||||||
{
|
},
|
||||||
ID: uuid.NewString(),
|
}
|
||||||
ServerID: uuid.NewString(),
|
client.ListServersReturnsOnCall(0, serversPL, nil)
|
||||||
ChannelGains: uuid.NewString(),
|
serversUK := []twhelp.Server{
|
||||||
ChannelLosses: "",
|
{
|
||||||
Internals: true,
|
Key: "uk51",
|
||||||
Barbarians: true,
|
URL: "https://uk51.tribalwars.co.uk",
|
||||||
ServerKey: "pl181",
|
Open: false,
|
||||||
VersionCode: "pl",
|
},
|
||||||
CreatedAt: time.Now().Add(-120 * time.Hour),
|
{
|
||||||
},
|
Key: "uk52",
|
||||||
{
|
URL: "https://uk52.tribalwars.co.uk",
|
||||||
ID: uuid.NewString(),
|
Open: false,
|
||||||
ServerID: uuid.NewString(),
|
},
|
||||||
ChannelGains: uuid.NewString(),
|
}
|
||||||
ChannelLosses: uuid.NewString(),
|
client.ListServersReturnsOnCall(1, serversUK, nil)
|
||||||
Internals: true,
|
client.ListServersReturnsOnCall(1, serversUK, nil)
|
||||||
Barbarians: true,
|
client.ListServersReturnsOnCall(2, nil, nil) // Turkey
|
||||||
ServerKey: "pl181",
|
|
||||||
VersionCode: "pl",
|
|
||||||
CreatedAt: time.Now().Add(-11 * time.Hour),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
repo.ListReturnsOnCall(1, groupsPL, nil)
|
|
||||||
groupsUK := []domain.Group{
|
|
||||||
{
|
|
||||||
ID: uuid.NewString(),
|
|
||||||
ServerID: uuid.NewString(),
|
|
||||||
ChannelGains: uuid.NewString(),
|
|
||||||
ChannelLosses: uuid.NewString(),
|
|
||||||
Internals: true,
|
|
||||||
Barbarians: true,
|
|
||||||
ServerKey: "uk51",
|
|
||||||
VersionCode: "uk",
|
|
||||||
CreatedAt: time.Now().Add(-150 * time.Hour),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ID: uuid.NewString(),
|
|
||||||
ServerID: uuid.NewString(),
|
|
||||||
ChannelGains: uuid.NewString(),
|
|
||||||
ChannelLosses: uuid.NewString(),
|
|
||||||
Internals: true,
|
|
||||||
Barbarians: true,
|
|
||||||
ServerKey: "uk52",
|
|
||||||
VersionCode: "uk",
|
|
||||||
CreatedAt: time.Now().Add(-200 * time.Hour),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
repo.ListReturnsOnCall(2, groupsUK, nil)
|
|
||||||
repo.DeleteManyReturns(nil)
|
|
||||||
|
|
||||||
client := &mock.FakeTWHelpClient{}
|
assert.NoError(t, service.NewGroup(repo, client, zap.NewNop(), 1).CleanUp(context.Background()))
|
||||||
versions := []twhelp.Version{
|
|
||||||
{
|
|
||||||
Code: "pl",
|
|
||||||
Host: "www.plemiona.pl",
|
|
||||||
Name: "Poland",
|
|
||||||
Timezone: "Europe/Warsaw",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Code: "uk",
|
|
||||||
Host: "www.tribalwars.co.uk",
|
|
||||||
Name: "United Kingdom",
|
|
||||||
Timezone: "Europe/London",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Code: "tr",
|
|
||||||
Host: "www.klanlar.org",
|
|
||||||
Name: "Turkey",
|
|
||||||
Timezone: "Europe/Istanbul",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
client.ListVersionsReturns(versions, nil)
|
|
||||||
serversPL := []twhelp.Server{
|
|
||||||
{
|
|
||||||
Key: "pl181",
|
|
||||||
URL: "https://pl181.plemiona.pl",
|
|
||||||
Open: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
client.ListServersReturnsOnCall(0, serversPL, nil)
|
|
||||||
serversUK := []twhelp.Server{
|
|
||||||
{
|
|
||||||
Key: "uk51",
|
|
||||||
URL: "https://uk51.tribalwars.co.uk",
|
|
||||||
Open: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "uk52",
|
|
||||||
URL: "https://uk52.tribalwars.co.uk",
|
|
||||||
Open: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
client.ListServersReturnsOnCall(1, serversUK, nil)
|
|
||||||
client.ListServersReturnsOnCall(1, serversUK, nil)
|
|
||||||
client.ListServersReturnsOnCall(2, nil, nil) // Turkey
|
|
||||||
|
|
||||||
assert.NoError(t, service.NewGroup(repo, client, zap.NewNop(), 1).CleanUp(context.Background()))
|
require.Equal(t, 3, repo.ListCallCount())
|
||||||
|
require.Equal(t, 3, repo.DeleteManyCallCount())
|
||||||
require.Equal(t, 3, repo.ListCallCount())
|
for _, tt := range []struct {
|
||||||
require.Equal(t, 3, repo.DeleteManyCallCount())
|
i int
|
||||||
for _, tt := range []struct {
|
groups []domain.Group
|
||||||
i int
|
}{
|
||||||
groups []domain.Group
|
{
|
||||||
}{
|
i: 0,
|
||||||
{
|
groups: groupsWithDisabledNotifications,
|
||||||
i: 0,
|
},
|
||||||
groups: groupsWithDisabledNotifications,
|
{
|
||||||
},
|
i: 1,
|
||||||
{
|
groups: groupsPL,
|
||||||
i: 1,
|
},
|
||||||
groups: groupsPL,
|
{
|
||||||
},
|
i: 2,
|
||||||
{
|
groups: groupsUK,
|
||||||
i: 2,
|
},
|
||||||
groups: groupsUK,
|
} {
|
||||||
},
|
_, ids := repo.DeleteManyArgsForCall(tt.i)
|
||||||
} {
|
assert.Len(t, ids, len(tt.groups))
|
||||||
_, ids := repo.DeleteManyArgsForCall(tt.i)
|
for i, id := range ids {
|
||||||
assert.Len(t, ids, len(tt.groups))
|
assert.Equal(t, tt.groups[i].ID, id)
|
||||||
for i, id := range ids {
|
|
||||||
assert.Equal(t, tt.groups[i].ID, id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
require.Equal(t, 1, client.ListVersionsCallCount())
|
require.Equal(t, 1, client.ListVersionsCallCount())
|
||||||
require.Equal(t, 3, client.ListServersCallCount())
|
require.Equal(t, 3, client.ListServersCallCount())
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user