Skip to content

Commit 35c1016

Browse files
iQQBotroboquat
authored andcommitted
[integration-test] allow mark user as unleashed plan
1 parent 8f336d5 commit 35c1016

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

test/pkg/integration/apis.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,53 @@ func (c *ComponentAPI) CreateUser(username string, token string) (string, error)
533533
return userId, nil
534534
}
535535

536+
func (c *ComponentAPI) MakeUserUnleashedPlan(username string) error {
537+
db, err := c.DB()
538+
if err != nil {
539+
return err
540+
}
541+
defer db.Close()
542+
543+
var userId string
544+
err = db.QueryRow(`SELECT id FROM d_b_user WHERE name = ?`, username).Scan(&userId)
545+
if err != nil {
546+
return err
547+
}
548+
549+
var subId string
550+
err = db.QueryRow(`SELECT uid FROM d_b_subscription WHERE userId = ? and planId = ?`, username, "professional-eur").Scan(&subId)
551+
if err != nil && !errors.Is(err, sql.ErrNoRows) {
552+
return err
553+
}
554+
if subId != "" {
555+
return nil
556+
}
557+
558+
// reset all of this user subscription
559+
_, err = db.Exec(`DELETE from d_b_subscription WHERE userId = ?`, userId)
560+
if err != nil {
561+
return err
562+
}
563+
564+
uid, err := uuid.NewRandom()
565+
if err != nil {
566+
return err
567+
}
568+
569+
_, err = db.Exec(`INSERT INTO d_b_subscription (uid, userId, startDate, amount, planId) VALUES (?, ?, ?, ?, ?)`,
570+
uid,
571+
userId,
572+
"2022-10-19T00:00:00.000Z",
573+
11904,
574+
"professional-eur",
575+
)
576+
if err != nil {
577+
return err
578+
}
579+
580+
return nil
581+
}
582+
536583
func (c *ComponentAPI) createGitpodToken(user string, scopes []string) (tkn string, err error) {
537584
id, err := c.GetUserId(user)
538585
if err != nil {

test/tests/ide/jetbrains/gateway_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ func TestJetBrainsGatewayWorkspace(t *testing.T) {
102102
if err != nil {
103103
t.Fatal(err)
104104
}
105+
err = api.MakeUserUnleashedPlan(username)
106+
if err != nil {
107+
t.Fatal(err)
108+
}
105109

106110
t.Logf("connecting to server...")
107111
server, err := api.GitpodServer(integration.WithGitpodUser(username))

0 commit comments

Comments
 (0)