2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2019-01-08 14:54:35 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
package consoleql_test
|
2019-01-08 14:54:35 +00:00
|
|
|
|
|
|
|
import (
|
2019-06-04 12:55:38 +01:00
|
|
|
"context"
|
2019-01-08 14:54:35 +00:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
2020-06-02 00:19:10 +01:00
|
|
|
"time"
|
2019-01-08 14:54:35 +00:00
|
|
|
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-05-17 14:31:14 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-01-31 13:01:13 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
2020-07-27 20:43:47 +01:00
|
|
|
"storj.io/common/testrand"
|
2020-03-30 10:08:50 +01:00
|
|
|
"storj.io/common/uuid"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/post"
|
2019-01-24 16:26:36 +00:00
|
|
|
"storj.io/storj/satellite"
|
2019-12-12 12:58:15 +00:00
|
|
|
"storj.io/storj/satellite/accounting"
|
|
|
|
"storj.io/storj/satellite/accounting/live"
|
2019-01-15 13:03:24 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
"storj.io/storj/satellite/console/consoleauth"
|
2019-01-24 16:26:36 +00:00
|
|
|
"storj.io/storj/satellite/console/consoleweb/consoleql"
|
2019-03-02 15:22:20 +00:00
|
|
|
"storj.io/storj/satellite/mailservice"
|
2020-05-18 10:17:05 +01:00
|
|
|
"storj.io/storj/satellite/payments/paymentsconfig"
|
|
|
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
2019-08-01 18:46:33 +01:00
|
|
|
"storj.io/storj/satellite/rewards"
|
2019-01-24 16:26:36 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2019-10-31 17:27:38 +00:00
|
|
|
"storj.io/storj/storage/redis/redisserver"
|
2019-01-08 14:54:35 +00:00
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// discardSender discard sending of an actual email.
|
2019-03-02 15:22:20 +00:00
|
|
|
type discardSender struct{}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// SendEmail immediately returns with nil error.
|
2019-06-04 12:55:38 +01:00
|
|
|
func (*discardSender) SendEmail(ctx context.Context, msg *post.Message) error {
|
2019-03-02 15:22:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// FromAddress returns empty post.Address.
|
2019-03-02 15:22:20 +00:00
|
|
|
func (*discardSender) FromAddress() post.Address {
|
|
|
|
return post.Address{}
|
|
|
|
}
|
|
|
|
|
2020-10-21 18:25:24 +01:00
|
|
|
func TestGraphqlMutation(t *testing.T) {
|
2020-01-19 16:29:15 +00:00
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
2019-01-31 13:01:13 +00:00
|
|
|
log := zaptest.NewLogger(t)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-11-05 12:58:09 +00:00
|
|
|
partnersService := rewards.NewPartnersService(
|
|
|
|
log.Named("partners"),
|
|
|
|
rewards.DefaultPartnersDB,
|
|
|
|
[]string{
|
|
|
|
"https://us-central-1.tardigrade.io/",
|
|
|
|
"https://asia-east-1.tardigrade.io/",
|
|
|
|
"https://europe-west-1.tardigrade.io/",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
redis, err := redisserver.Mini(ctx)
|
2019-10-31 17:27:38 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-31 18:28:42 +00:00
|
|
|
defer ctx.Check(redis.Close)
|
2019-10-31 17:27:38 +00:00
|
|
|
|
2020-01-31 18:28:42 +00:00
|
|
|
cache, err := live.NewCache(log.Named("cache"), live.Config{StorageBackend: "redis://" + redis.Addr() + "?db=0"})
|
2019-12-12 12:58:15 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-09 20:20:44 +01:00
|
|
|
projectLimitCache := accounting.NewProjectLimitCache(db.ProjectAccounting(), 0, 0, accounting.ProjectLimitConfig{CacheCapacity: 100})
|
|
|
|
|
|
|
|
projectUsage := accounting.NewService(db.ProjectAccounting(), cache, projectLimitCache, 5*time.Minute)
|
2019-10-17 15:42:18 +01:00
|
|
|
|
2020-05-18 10:17:05 +01:00
|
|
|
// TODO maybe switch this test to testplanet to avoid defining config and Stripe service
|
|
|
|
pc := paymentsconfig.Config{
|
|
|
|
StorageTBPrice: "10",
|
|
|
|
EgressTBPrice: "45",
|
|
|
|
ObjectPrice: "0.0000022",
|
|
|
|
}
|
|
|
|
|
|
|
|
paymentsService, err := stripecoinpayments.NewService(
|
|
|
|
log.Named("payments.stripe:service"),
|
2020-10-08 18:14:09 +01:00
|
|
|
stripecoinpayments.NewStripeMock(
|
|
|
|
testrand.NodeID(),
|
|
|
|
db.StripeCoinPayments().Customers(),
|
|
|
|
db.Console().Users(),
|
|
|
|
),
|
2020-05-18 10:17:05 +01:00
|
|
|
pc.StripeCoinPayments,
|
|
|
|
db.StripeCoinPayments(),
|
|
|
|
db.Console().Projects(),
|
|
|
|
db.ProjectAccounting(),
|
|
|
|
pc.StorageTBPrice,
|
|
|
|
pc.EgressTBPrice,
|
|
|
|
pc.ObjectPrice,
|
|
|
|
pc.BonusRate,
|
|
|
|
pc.CouponValue,
|
|
|
|
pc.CouponDuration,
|
|
|
|
pc.CouponProjectLimit,
|
2020-07-10 14:05:17 +01:00
|
|
|
pc.MinCoinPayment,
|
|
|
|
pc.PaywallProportion)
|
2020-05-18 10:17:05 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
service, err := console.NewService(
|
2019-12-12 12:58:15 +00:00
|
|
|
log.Named("console"),
|
2019-01-24 16:26:36 +00:00
|
|
|
&consoleauth.Hmac{Secret: []byte("my-suppa-secret-key")},
|
|
|
|
db.Console(),
|
2019-11-15 14:27:44 +00:00
|
|
|
db.ProjectAccounting(),
|
2019-12-12 12:58:15 +00:00
|
|
|
projectUsage,
|
2020-10-09 14:40:12 +01:00
|
|
|
db.Buckets(),
|
2019-07-02 15:36:54 +01:00
|
|
|
db.Rewards(),
|
2019-11-05 12:58:09 +00:00
|
|
|
partnersService,
|
2020-05-18 10:17:05 +01:00
|
|
|
paymentsService.Accounts(),
|
2020-07-15 17:49:37 +01:00
|
|
|
console.Config{PasswordCost: console.TestPasswordCost, DefaultProjectLimit: 5},
|
2020-03-16 19:34:15 +00:00
|
|
|
5000,
|
2019-01-08 14:54:35 +00:00
|
|
|
)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-24 16:26:36 +00:00
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
mailService, err := mailservice.New(log, &discardSender{}, "testdata")
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-05-17 13:29:35 +01:00
|
|
|
defer ctx.Check(mailService.Close)
|
2019-03-02 15:22:20 +00:00
|
|
|
|
|
|
|
rootObject := make(map[string]interface{})
|
|
|
|
rootObject["origin"] = "http://doesntmatter.com/"
|
|
|
|
rootObject[consoleql.ActivationPath] = "?activationToken="
|
2019-03-26 15:56:16 +00:00
|
|
|
rootObject[consoleql.SignInPath] = "login"
|
2019-09-27 17:48:53 +01:00
|
|
|
rootObject[consoleql.LetUsKnowURL] = "letUsKnowURL"
|
|
|
|
rootObject[consoleql.ContactInfoURL] = "contactInfoURL"
|
|
|
|
rootObject[consoleql.TermsAndConditionsURL] = "termsAndConditionsURL"
|
2019-03-02 15:22:20 +00:00
|
|
|
|
2019-03-26 15:56:16 +00:00
|
|
|
schema, err := consoleql.CreateSchema(log, service, mailService)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
createUser := console.CreateUser{
|
2019-10-29 14:24:16 +00:00
|
|
|
FullName: "John Roll",
|
|
|
|
ShortName: "Roll",
|
|
|
|
Email: "test@mail.test",
|
|
|
|
PartnerID: "120bf202-8252-437e-ac12-0e364bee852e",
|
|
|
|
Password: "123a123",
|
2019-01-08 14:54:35 +00:00
|
|
|
}
|
2019-07-23 17:08:07 +01:00
|
|
|
refUserID := ""
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
regToken, err := service.CreateRegToken(ctx, 1)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-03-19 17:55:43 +00:00
|
|
|
|
2019-07-23 17:08:07 +01:00
|
|
|
rootUser, err := service.CreateUser(ctx, createUser, regToken.Secret, refUserID)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-07-17 21:53:14 +01:00
|
|
|
require.Equal(t, createUser.PartnerID, rootUser.PartnerID.String())
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-05-18 10:17:05 +01:00
|
|
|
err = paymentsService.Accounts().Setup(ctx, rootUser.ID, rootUser.Email)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-03-08 14:01:11 +00:00
|
|
|
activationToken, err := service.GenerateActivationToken(ctx, rootUser.ID, rootUser.Email)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-30 15:04:40 +00:00
|
|
|
|
2019-03-08 14:01:11 +00:00
|
|
|
err = service.ActivateAccount(ctx, activationToken)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-30 15:04:40 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
token, err := service.Token(ctx, createUser.Email, createUser.Password)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-24 16:26:36 +00:00
|
|
|
|
2020-10-06 11:40:31 +01:00
|
|
|
sauth, err := service.Authorize(consoleauth.WithAPIKey(ctx, []byte(token)))
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
authCtx := console.WithAuth(ctx, sauth)
|
|
|
|
|
2020-10-06 15:25:53 +01:00
|
|
|
testQuery := func(t *testing.T, query string) (interface{}, error) {
|
2019-01-24 16:26:36 +00:00
|
|
|
result := graphql.Do(graphql.Params{
|
|
|
|
Schema: schema,
|
|
|
|
Context: authCtx,
|
|
|
|
RequestString: query,
|
2019-03-02 15:22:20 +00:00
|
|
|
RootObject: rootObject,
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
for _, err := range result.Errors {
|
2020-10-06 15:25:53 +01:00
|
|
|
if err.OriginalError() != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-01-24 16:26:36 +00:00
|
|
|
}
|
2019-05-17 14:31:14 +01:00
|
|
|
require.False(t, result.HasErrors())
|
2019-01-24 16:26:36 +00:00
|
|
|
|
2020-10-06 15:25:53 +01:00
|
|
|
return result.Data, nil
|
2019-01-08 14:54:35 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
token, err = service.Token(ctx, rootUser.Email, createUser.Password)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-10-06 11:40:31 +01:00
|
|
|
sauth, err = service.Authorize(consoleauth.WithAPIKey(ctx, []byte(token)))
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
authCtx = console.WithAuth(ctx, sauth)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-04-02 13:30:43 +01:00
|
|
|
var projectIDField string
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Create project mutation", func(t *testing.T) {
|
|
|
|
projectInfo := console.ProjectInfo{
|
|
|
|
Name: "Project name",
|
|
|
|
Description: "desc",
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
query := fmt.Sprintf(
|
2019-01-28 18:20:33 +00:00
|
|
|
"mutation {createProject(input:{name:\"%s\",description:\"%s\"}){name,description,id,createdAt}}",
|
2019-01-24 16:26:36 +00:00
|
|
|
projectInfo.Name,
|
|
|
|
projectInfo.Description,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-10-06 15:25:53 +01:00
|
|
|
result, err := testQuery(t, query)
|
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
project := data[consoleql.CreateProjectMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, projectInfo.Name, project[consoleql.FieldName])
|
|
|
|
assert.Equal(t, projectInfo.Description, project[consoleql.FieldDescription])
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-04-02 13:30:43 +01:00
|
|
|
projectIDField = project[consoleql.FieldID].(string)
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-04-02 13:30:43 +01:00
|
|
|
projectID, err := uuid.FromString(projectIDField)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-04-02 13:30:43 +01:00
|
|
|
project, err := service.GetProject(authCtx, projectID)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-08-12 22:29:40 +01:00
|
|
|
require.Equal(t, rootUser.PartnerID, project.PartnerID)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
regTokenUser1, err := service.CreateRegToken(ctx, 1)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-03-19 17:55:43 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
user1, err := service.CreateUser(authCtx, console.CreateUser{
|
2019-10-29 14:24:16 +00:00
|
|
|
FullName: "User1",
|
|
|
|
Email: "u1@mail.test",
|
2019-01-24 16:26:36 +00:00
|
|
|
Password: "123a123",
|
2019-07-23 17:08:07 +01:00
|
|
|
}, regTokenUser1.Secret, refUserID)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-02-05 17:22:17 +00:00
|
|
|
t.Run("Activation", func(t *testing.T) {
|
|
|
|
activationToken1, err := service.GenerateActivationToken(
|
|
|
|
ctx,
|
|
|
|
user1.ID,
|
2019-06-18 01:28:40 +01:00
|
|
|
"u1@mail.test",
|
2019-02-05 17:22:17 +00:00
|
|
|
)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-03-08 14:01:11 +00:00
|
|
|
err = service.ActivateAccount(ctx, activationToken1)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-06-18 01:28:40 +01:00
|
|
|
user1.Email = "u1@mail.test"
|
2019-02-05 17:22:17 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
regTokenUser2, err := service.CreateRegToken(ctx, 1)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-03-19 17:55:43 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
user2, err := service.CreateUser(authCtx, console.CreateUser{
|
2019-10-29 14:24:16 +00:00
|
|
|
FullName: "User1",
|
|
|
|
Email: "u2@mail.test",
|
2019-01-24 16:26:36 +00:00
|
|
|
Password: "123a123",
|
2019-07-23 17:08:07 +01:00
|
|
|
}, regTokenUser2.Secret, refUserID)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-02-05 17:22:17 +00:00
|
|
|
|
|
|
|
t.Run("Activation", func(t *testing.T) {
|
|
|
|
activationToken2, err := service.GenerateActivationToken(
|
|
|
|
ctx,
|
|
|
|
user2.ID,
|
2019-06-18 01:28:40 +01:00
|
|
|
"u2@mail.test",
|
2019-02-05 17:22:17 +00:00
|
|
|
)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-03-08 14:01:11 +00:00
|
|
|
err = service.ActivateAccount(ctx, activationToken2)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-06-18 01:28:40 +01:00
|
|
|
user2.Email = "u2@mail.test"
|
2019-02-05 17:22:17 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Add project members mutation", func(t *testing.T) {
|
|
|
|
query := fmt.Sprintf(
|
2019-08-12 11:22:32 +01:00
|
|
|
"mutation {addProjectMembers(projectID:\"%s\",email:[\"%s\",\"%s\"]){id,name,members(cursor: { limit: 50, search: \"\", page: 1, order: 1, orderDirection: 2 }){projectMembers{joinedAt}}}}",
|
2019-01-24 16:26:36 +00:00
|
|
|
project.ID.String(),
|
|
|
|
user1.Email,
|
|
|
|
user2.Email,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-10-06 15:25:53 +01:00
|
|
|
result, err := testQuery(t, query)
|
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
proj := data[consoleql.AddProjectMembersMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-08-12 11:22:32 +01:00
|
|
|
members := proj[consoleql.FieldMembers].(map[string]interface{})
|
|
|
|
projectMembers := members[consoleql.FieldProjectMembers].([]interface{})
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, project.ID.String(), proj[consoleql.FieldID])
|
|
|
|
assert.Equal(t, project.Name, proj[consoleql.FieldName])
|
2019-08-12 11:22:32 +01:00
|
|
|
assert.Equal(t, 3, len(projectMembers))
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Delete project members mutation", func(t *testing.T) {
|
|
|
|
query := fmt.Sprintf(
|
2019-08-12 11:22:32 +01:00
|
|
|
"mutation {deleteProjectMembers(projectID:\"%s\",email:[\"%s\",\"%s\"]){id,name,members(cursor: { limit: 50, search: \"\", page: 1, order: 1, orderDirection: 2 }){projectMembers{user{id}}}}}",
|
2019-01-24 16:26:36 +00:00
|
|
|
project.ID.String(),
|
|
|
|
user1.Email,
|
|
|
|
user2.Email,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-10-06 15:25:53 +01:00
|
|
|
result, err := testQuery(t, query)
|
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
proj := data[consoleql.DeleteProjectMembersMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-08-12 11:22:32 +01:00
|
|
|
members := proj[consoleql.FieldMembers].(map[string]interface{})
|
|
|
|
projectMembers := members[consoleql.FieldProjectMembers].([]interface{})
|
|
|
|
rootMember := projectMembers[0].(map[string]interface{})[consoleql.UserType].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, project.ID.String(), proj[consoleql.FieldID])
|
|
|
|
assert.Equal(t, project.Name, proj[consoleql.FieldName])
|
|
|
|
assert.Equal(t, 1, len(members))
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, rootUser.ID.String(), rootMember[consoleql.FieldID])
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
var keyID string
|
|
|
|
t.Run("Create api key mutation", func(t *testing.T) {
|
|
|
|
keyName := "key1"
|
|
|
|
query := fmt.Sprintf(
|
2019-07-17 21:53:14 +01:00
|
|
|
"mutation {createAPIKey(projectID:\"%s\",name:\"%s\"){key,keyInfo{id,name,projectID,partnerId}}}",
|
2019-01-24 16:26:36 +00:00
|
|
|
project.ID.String(),
|
|
|
|
keyName,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-10-06 15:25:53 +01:00
|
|
|
result, err := testQuery(t, query)
|
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
createAPIKey := data[consoleql.CreateAPIKeyMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
key := createAPIKey[consoleql.FieldKey].(string)
|
|
|
|
keyInfo := createAPIKey[consoleql.APIKeyInfoType].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.NotEqual(t, "", key)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, keyName, keyInfo[consoleql.FieldName])
|
|
|
|
assert.Equal(t, project.ID.String(), keyInfo[consoleql.FieldProjectID])
|
2019-07-17 21:53:14 +01:00
|
|
|
assert.Equal(t, rootUser.PartnerID.String(), keyInfo[consoleql.FieldPartnerID])
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
keyID = keyInfo[consoleql.FieldID].(string)
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Delete api key mutation", func(t *testing.T) {
|
2020-04-02 13:30:43 +01:00
|
|
|
id, err := uuid.FromString(keyID)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-04-02 13:30:43 +01:00
|
|
|
info, err := service.GetAPIKeyInfo(authCtx, id)
|
2019-05-17 14:31:14 +01:00
|
|
|
require.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
query := fmt.Sprintf(
|
2019-02-13 11:34:40 +00:00
|
|
|
"mutation {deleteAPIKeys(id:[\"%s\"]){name,projectID}}",
|
|
|
|
keyID,
|
2019-01-24 16:26:36 +00:00
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-10-06 15:25:53 +01:00
|
|
|
result, err := testQuery(t, query)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
2019-02-13 11:34:40 +00:00
|
|
|
keyInfoList := data[consoleql.DeleteAPIKeysMutation].([]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-02-13 11:34:40 +00:00
|
|
|
for _, k := range keyInfoList {
|
|
|
|
keyInfo := k.(map[string]interface{})
|
|
|
|
|
|
|
|
assert.Equal(t, info.Name, keyInfo[consoleql.FieldName])
|
|
|
|
assert.Equal(t, project.ID.String(), keyInfo[consoleql.FieldProjectID])
|
|
|
|
}
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-09-10 10:32:35 +01:00
|
|
|
const testName = "testName"
|
|
|
|
const testDescription = "test description"
|
|
|
|
|
|
|
|
t.Run("Update project mutation", func(t *testing.T) {
|
|
|
|
query := fmt.Sprintf(
|
|
|
|
"mutation {updateProject(id:\"%s\",name:\"%s\",description:\"%s\"){id,name,description}}",
|
|
|
|
project.ID.String(),
|
|
|
|
testName,
|
|
|
|
testDescription,
|
|
|
|
)
|
|
|
|
|
2020-10-06 15:25:53 +01:00
|
|
|
result, err := testQuery(t, query)
|
|
|
|
require.NoError(t, err)
|
2020-09-10 10:32:35 +01:00
|
|
|
|
|
|
|
data := result.(map[string]interface{})
|
|
|
|
proj := data[consoleql.UpdateProjectMutation].(map[string]interface{})
|
|
|
|
|
|
|
|
assert.Equal(t, project.ID.String(), proj[consoleql.FieldID])
|
|
|
|
assert.Equal(t, testName, proj[consoleql.FieldName])
|
|
|
|
assert.Equal(t, testDescription, proj[consoleql.FieldDescription])
|
|
|
|
})
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Delete project mutation", func(t *testing.T) {
|
|
|
|
query := fmt.Sprintf(
|
|
|
|
"mutation {deleteProject(id:\"%s\"){id,name}}",
|
|
|
|
projectID,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2020-10-06 15:25:53 +01:00
|
|
|
result, err := testQuery(t, query)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, result)
|
|
|
|
require.Equal(t, console.ErrUnauthorized.New("not implemented").Error(), err.Error())
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
})
|
|
|
|
}
|