2019-01-31 13:01:13 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package console_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-01-17 15:01:36 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-01-31 13:01:13 +00:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2019-01-31 13:01:13 +00:00
|
|
|
"storj.io/storj/satellite"
|
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProjectsRepository(t *testing.T) {
|
|
|
|
//testing constants
|
|
|
|
const (
|
|
|
|
// for user
|
2019-03-27 12:33:32 +00:00
|
|
|
shortName = "lastName"
|
2019-06-18 01:28:40 +01:00
|
|
|
email = "email@mail.test"
|
2019-03-27 12:33:32 +00:00
|
|
|
pass = "123456"
|
|
|
|
userFullName = "name"
|
2019-01-31 13:01:13 +00:00
|
|
|
|
|
|
|
// for project
|
|
|
|
name = "Project"
|
|
|
|
description = "some description"
|
|
|
|
|
|
|
|
// updated project values
|
|
|
|
newDescription = "some new description"
|
|
|
|
)
|
|
|
|
|
2020-01-19 16:29:15 +00:00
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) { // repositories
|
2019-01-31 13:01:13 +00:00
|
|
|
users := db.Console().Users()
|
|
|
|
projects := db.Console().Projects()
|
|
|
|
var project *console.Project
|
|
|
|
var owner *console.User
|
|
|
|
|
2020-01-17 15:01:36 +00:00
|
|
|
rateLimit := 100
|
2019-01-31 13:01:13 +00:00
|
|
|
t.Run("Insert project successfully", func(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
owner, err = users.Insert(ctx, &console.User{
|
2019-11-20 19:16:27 +00:00
|
|
|
ID: testrand.UUID(),
|
2019-03-27 12:33:32 +00:00
|
|
|
FullName: userFullName,
|
|
|
|
ShortName: shortName,
|
2019-01-31 13:01:13 +00:00
|
|
|
Email: email,
|
|
|
|
PasswordHash: []byte(pass),
|
|
|
|
})
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, owner)
|
2019-01-31 13:01:13 +00:00
|
|
|
|
|
|
|
project = &console.Project{
|
|
|
|
Name: name,
|
|
|
|
Description: description,
|
2019-08-07 13:28:13 +01:00
|
|
|
OwnerID: owner.ID,
|
2020-01-17 15:01:36 +00:00
|
|
|
RateLimit: &rateLimit,
|
2019-01-31 13:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
project, err = projects.Insert(ctx, project)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NotNil(t, project)
|
|
|
|
require.NoError(t, err)
|
2019-01-31 13:01:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get by projectID success", func(t *testing.T) {
|
|
|
|
projectByID, err := projects.Get(ctx, project.ID)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, project.ID, projectByID.ID)
|
|
|
|
require.Equal(t, name, projectByID.Name)
|
|
|
|
require.Equal(t, owner.ID, projectByID.OwnerID)
|
|
|
|
require.Equal(t, description, projectByID.Description)
|
|
|
|
require.Equal(t, rateLimit, *projectByID.RateLimit)
|
2019-01-31 13:01:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Update project success", func(t *testing.T) {
|
|
|
|
oldProject, err := projects.Get(ctx, project.ID)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, oldProject)
|
|
|
|
|
|
|
|
newRateLimit := 1000
|
2019-01-31 13:01:13 +00:00
|
|
|
|
|
|
|
// creating new project with updated values
|
|
|
|
newProject := &console.Project{
|
|
|
|
ID: oldProject.ID,
|
|
|
|
Description: newDescription,
|
2020-01-17 15:01:36 +00:00
|
|
|
RateLimit: &newRateLimit,
|
2019-01-31 13:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = projects.Update(ctx, newProject)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
2019-01-31 13:01:13 +00:00
|
|
|
|
|
|
|
// fetching updated project from db
|
|
|
|
newProject, err = projects.Get(ctx, oldProject.ID)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, oldProject.ID, newProject.ID)
|
|
|
|
require.Equal(t, newDescription, newProject.Description)
|
|
|
|
require.Equal(t, newRateLimit, *newProject.RateLimit)
|
2019-01-31 13:01:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete project success", func(t *testing.T) {
|
|
|
|
oldProject, err := projects.Get(ctx, project.ID)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, oldProject)
|
2019-01-31 13:01:13 +00:00
|
|
|
|
|
|
|
err = projects.Delete(ctx, oldProject.ID)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
2019-01-31 13:01:13 +00:00
|
|
|
|
|
|
|
_, err = projects.Get(ctx, oldProject.ID)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.Error(t, err)
|
2019-01-31 13:01:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetAll success", func(t *testing.T) {
|
|
|
|
allProjects, err := projects.GetAll(ctx)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 0, len(allProjects))
|
2019-01-31 13:01:13 +00:00
|
|
|
|
|
|
|
newProject := &console.Project{
|
|
|
|
Description: description,
|
|
|
|
Name: name,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = projects.Insert(ctx, newProject)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
2019-01-31 13:01:13 +00:00
|
|
|
|
|
|
|
allProjects, err = projects.GetAll(ctx)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(allProjects))
|
2019-01-31 13:01:13 +00:00
|
|
|
|
|
|
|
newProject2 := &console.Project{
|
|
|
|
Description: description,
|
2019-02-05 17:22:17 +00:00
|
|
|
Name: name + "2",
|
2019-01-31 13:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = projects.Insert(ctx, newProject2)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
2019-01-31 13:01:13 +00:00
|
|
|
|
|
|
|
allProjects, err = projects.GetAll(ctx)
|
2020-01-17 15:01:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, len(allProjects))
|
2019-01-31 13:01:13 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|