Skip to content

Commit 3b9dca1

Browse files
authored
RI-6931: Require login on every free cloud db creation (#260)
* introduce a REQUIRE_LOGIN_ON_NEW_DB constant, as there is no logout functionality and the user should be able to create free DBs with different accounts * modify existing test and add new ones depending on the REQUIRE_LOGIN_ON_NEW_DB value
1 parent 024c472 commit 3b9dca1

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

src/webviews/src/modules/oauth/oauth-sso/oauth-create-db/OAuthCreateDb.spec.tsx

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { initialOAuthState, useOAuthStore } from 'uiSrc/store'
88
import { INFINITE_MESSAGES } from 'uiSrc/components'
99
import { act, cleanup, constants, fireEvent, render, screen } from 'testSrc/helpers'
1010
import OAuthCreateDb from './OAuthCreateDb'
11+
import { REQUIRE_LOGIN_ON_NEW_DB } from './constants'
1112

1213
vi.spyOn(utils, 'sendEventTelemetry')
1314
vi.spyOn(utils, 'showInfinityToast')
@@ -85,18 +86,66 @@ describe('OAuthCreateDb', () => {
8586
})
8687
})
8788

88-
it('should render proper components if user is logged in', () => {
89+
it('should call proper actions after click on sign button w/o recommended settings', async () => {
90+
render(<OAuthCreateDb />)
91+
92+
await act(async () => {
93+
fireEvent.click(screen.getByTestId('oauth-recommended-settings-checkbox'))
94+
})
95+
96+
fireEvent.click(screen.getByTestId('google-oauth'))
97+
98+
expect(sendEventTelemetry).toBeCalledWith({
99+
event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED,
100+
eventData: {
101+
accountOption: OAuthStrategy.Google,
102+
action: OAuthSocialAction.Create,
103+
cloudRecommendedSettings: 'disabled',
104+
},
105+
})
106+
107+
expect(useOAuthStore.getState().isOpenSocialDialog).toEqual(false)
108+
})
109+
110+
it.skipIf(REQUIRE_LOGIN_ON_NEW_DB)('should render proper components when user is logged in', () => {
111+
useOAuthStore.setState({ ...initialOAuthState,
112+
agreement: true,
113+
user: {
114+
...initialOAuthState.user,
115+
data: {},
116+
},
117+
})
118+
119+
render(<OAuthCreateDb />)
120+
121+
expect(screen.getByTestId('oauth-advantages')).toBeInTheDocument()
122+
expect(screen.getByTestId('oauth-recommended-settings-checkbox')).toBeInTheDocument()
123+
expect(screen.getByTestId('oauth-create-db')).toBeInTheDocument()
124+
125+
expect(screen.queryByTestId('oauth-agreement-checkbox')).not.toBeInTheDocument()
126+
expect(screen.queryByTestId('oauth-container-social-buttons')).not.toBeInTheDocument()
127+
})
128+
129+
it.skipIf(!REQUIRE_LOGIN_ON_NEW_DB)('should render oauth form elements if user logged in', () => {
130+
useOAuthStore.setState({ ...initialOAuthState,
131+
agreement: true,
132+
user: {
133+
...initialOAuthState.user,
134+
data: {},
135+
},
136+
})
137+
89138
render(<OAuthCreateDb />)
90139

91140
expect(screen.getByTestId('oauth-advantages')).toBeInTheDocument()
92-
// expect(screen.getByTestId('oauth-create-db')).toBeInTheDocument()
93141
expect(screen.getByTestId('oauth-recommended-settings-checkbox')).toBeInTheDocument()
142+
expect(screen.getByTestId('oauth-agreement-checkbox')).toBeInTheDocument()
143+
expect(screen.getByTestId('oauth-container-social-buttons')).toBeInTheDocument()
94144

95-
// expect(screen.queryByTestId('oauth-agreement-checkbox')).not.toBeInTheDocument()
96-
// expect(screen.queryByTestId('oauth-container-social-buttons')).not.toBeInTheDocument()
145+
expect(screen.queryByTestId('oauth-create-db')).not.toBeInTheDocument()
97146
})
98147

99-
it('should call proper actions after click create', async () => {
148+
it.skipIf(REQUIRE_LOGIN_ON_NEW_DB)('should call proper actions after click create', async () => {
100149
const name = CloudJobName.CreateFreeSubscriptionAndDatabase
101150
useOAuthStore.setState({ ...initialOAuthState,
102151
agreement: true,
@@ -120,7 +169,7 @@ describe('OAuthCreateDb', () => {
120169
)
121170
})
122171

123-
it('should call proper actions after click create without recommened settings', async () => {
172+
it.skipIf(REQUIRE_LOGIN_ON_NEW_DB)('should call proper actions after click create without recommened settings', async () => {
124173
useOAuthStore.setState({ ...initialOAuthState,
125174
agreement: true,
126175
source: 'source',

src/webviews/src/modules/oauth/oauth-sso/oauth-create-db/OAuthCreateDb.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { createFreeDbJob, fetchCloudSubscriptionPlans, useOAuthStore } from 'uiS
1010
import { Spacer } from 'uiSrc/ui'
1111
import { INFINITE_MESSAGES } from 'uiSrc/components'
1212

13+
import { REQUIRE_LOGIN_ON_NEW_DB } from './constants'
1314
import { OAuthForm } from '../../shared/oauth-form'
1415
import OAuthAgreement from '../../shared/oauth-agreement/OAuthAgreement'
1516
import { OAuthAdvantages, OAuthRecommendedSettings } from '../../shared'
@@ -85,7 +86,7 @@ const OAuthCreateDb = (props: Props) => {
8586
<OAuthAdvantages />
8687
</div>
8788
<div className={styles.socialContainer}>
88-
{!data ? (
89+
{!data || REQUIRE_LOGIN_ON_NEW_DB ? (
8990
<OAuthForm
9091
className={styles.socialButtons}
9192
onClick={handleSocialButtonClick}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// TODO [DA]: Remove once logout is implemented and it is decided that this functionality no longer needed
2+
// Added in order to give flexibility to the user to login every time and change cloud accounts
3+
// on each create free db event
4+
export const REQUIRE_LOGIN_ON_NEW_DB: boolean = true

0 commit comments

Comments
 (0)