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) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
repo := &mock.FakeGroupRepository{}
|
||||
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{}
|
||||
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)
|
||||
client := &mock.FakeTWHelpClient{}
|
||||
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
|
||||
|
||||
client := &mock.FakeTWHelpClient{}
|
||||
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()))
|
||||
|
||||
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())
|
||||
for _, tt := range []struct {
|
||||
i int
|
||||
groups []domain.Group
|
||||
}{
|
||||
{
|
||||
i: 0,
|
||||
groups: groupsWithDisabledNotifications,
|
||||
},
|
||||
{
|
||||
i: 1,
|
||||
groups: groupsPL,
|
||||
},
|
||||
{
|
||||
i: 2,
|
||||
groups: groupsUK,
|
||||
},
|
||||
} {
|
||||
_, ids := repo.DeleteManyArgsForCall(tt.i)
|
||||
assert.Len(t, ids, len(tt.groups))
|
||||
for i, id := range ids {
|
||||
assert.Equal(t, tt.groups[i].ID, id)
|
||||
}
|
||||
require.Equal(t, 3, repo.ListCallCount())
|
||||
require.Equal(t, 3, repo.DeleteManyCallCount())
|
||||
for _, tt := range []struct {
|
||||
i int
|
||||
groups []domain.Group
|
||||
}{
|
||||
{
|
||||
i: 0,
|
||||
groups: groupsWithDisabledNotifications,
|
||||
},
|
||||
{
|
||||
i: 1,
|
||||
groups: groupsPL,
|
||||
},
|
||||
{
|
||||
i: 2,
|
||||
groups: groupsUK,
|
||||
},
|
||||
} {
|
||||
_, ids := repo.DeleteManyArgsForCall(tt.i)
|
||||
assert.Len(t, ids, len(tt.groups))
|
||||
for i, id := range ids {
|
||||
assert.Equal(t, tt.groups[i].ID, id)
|
||||
}
|
||||
}
|
||||
|
||||
require.Equal(t, 1, client.ListVersionsCallCount())
|
||||
require.Equal(t, 3, client.ListServersCallCount())
|
||||
})
|
||||
require.Equal(t, 1, client.ListVersionsCallCount())
|
||||
require.Equal(t, 3, client.ListServersCallCount())
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user