summaryrefslogtreecommitdiff
path: root/internal/suites/scenario_change_password_test.go
blob: 8419a4f5c1ba581b36dadc9e131df018266416dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package suites

import (
	"context"
	"log"
	"testing"
	"time"
)

type ChangePasswordScenario struct {
	*RodSuite
}

func NewChangePasswordScenario() *ChangePasswordScenario {
	return &ChangePasswordScenario{RodSuite: NewRodSuite("")}
}

func (s *ChangePasswordScenario) SetupSuite() {
	browser, err := NewRodSession(RodSessionWithCredentials(s))
	if err != nil {
		log.Fatal(err)
	}

	s.RodSession = browser
}

func (s *ChangePasswordScenario) TearDownSuite() {
	err := s.RodSession.Stop()

	if err != nil {
		log.Fatal(err)
	}
}

func (s *ChangePasswordScenario) SetupTest() {
	s.Page = s.doCreateTab(s.T(), HomeBaseURL)
	s.verifyIsHome(s.T(), s.Page)
}

func (s *ChangePasswordScenario) TearDownTest() {
	s.collectCoverage(s.Page)
	s.MustClose()
}

func (s *ChangePasswordScenario) TestShouldChangePassword() {
	testCases := []struct {
		name        string
		username    string
		oldPassword string
		newPassword string
	}{
		{"case1", "john", "password", "password1"},
		{"case2", "john", "password1", "password"},
	}

	for _, tc := range testCases {
		s.T().Run(tc.name, func(t *testing.T) {
			ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
			defer func() {
				cancel()
				s.collectScreenshot(ctx.Err(), s.Page)
			}()
			s.doLoginOneFactor(s.T(), s.Context(ctx), tc.username, tc.oldPassword, false, BaseDomain, "")
			s.doOpenSettings(s.T(), s.Context(ctx))
			s.doOpenSettingsMenuClickSecurity(s.T(), s.Context(ctx))

			s.doChangePassword(s.T(), s.Context(ctx), tc.oldPassword, tc.newPassword, tc.newPassword)
			s.doLogout(s.T(), s.Context(ctx))
		})
	}
}

func (s *ChangePasswordScenario) TestCannotChangePasswordToExistingPassword() {
	testCases := []struct {
		testName    string
		username    string
		oldPassword string
	}{
		{"case1", "john", "password"},
	}

	for _, tc := range testCases {
		s.T().Run(tc.testName, func(t *testing.T) {
			ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
			defer func() {
				cancel()
				s.collectScreenshot(ctx.Err(), s.Page)
			}()
			s.doLoginOneFactor(s.T(), s.Context(ctx), tc.username, tc.oldPassword, false, BaseDomain, "")
			s.doOpenSettings(s.T(), s.Context(ctx))
			s.doOpenSettingsMenuClickSecurity(s.T(), s.Context(ctx))

			s.doMustChangePasswordExistingPassword(s.T(), s.Context(ctx), tc.oldPassword)

			s.doLogout(s.T(), s.Context(ctx))
		})
	}
}

func (s *ChangePasswordScenario) TestCannotChangePasswordWithIncorrectOldPassword() {
	testCases := []struct {
		testName         string
		username         string
		oldPassword      string
		wrongOldPassword string
		newPassword      string
	}{
		{"case1", "john", "password", "wrong_password", "new_password"},
	}

	for _, tc := range testCases {
		s.T().Run(tc.testName, func(t *testing.T) {
			ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
			defer func() {
				cancel()
				s.collectScreenshot(ctx.Err(), s.Page)
			}()
			s.doLoginOneFactor(s.T(), s.Context(ctx), tc.username, tc.oldPassword, false, BaseDomain, "")

			s.doOpenSettings(s.T(), s.Context(ctx))

			s.doOpenSettingsMenuClickSecurity(s.T(), s.Context(ctx))

			s.doMustChangePasswordWrongExistingPassword(s.T(), s.Context(ctx), tc.wrongOldPassword, tc.newPassword)

			s.doLogout(s.T(), s.Context(ctx))
		})
	}
}

func (s *ChangePasswordScenario) TestNewPasswordsMustMatch() {
	testCases := []struct {
		testName     string
		username     string
		oldPassword  string
		newPassword1 string
		newPassword2 string
	}{
		{"case1", "john", "password", "my_new_password", "new_password"},
	}

	for _, tc := range testCases {
		s.T().Run(tc.testName, func(t *testing.T) {
			ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
			defer func() {
				cancel()
				s.collectScreenshot(ctx.Err(), s.Page)
			}()
			s.doLoginOneFactor(s.T(), s.Context(ctx), tc.username, tc.oldPassword, false, BaseDomain, "")

			s.doOpenSettings(s.T(), s.Context(ctx))

			s.doOpenSettingsMenuClickSecurity(s.T(), s.Context(ctx))

			s.doMustChangePasswordMustMatch(s.T(), s.Context(ctx), tc.oldPassword, tc.newPassword1, tc.newPassword2)

			s.doLogout(s.T(), s.Context(ctx))
		})
	}
}