Skip to content

Commit

Permalink
Merge branch '2362-okta' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Dec 19, 2023
2 parents 04958ef + e0319ab commit d41d50c
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/app/branded/branded-checkout.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BrandedCheckoutController {
this.analyticsFactory.pageLoaded(true)
this.formatDonorDetails()

this.sessionService.oktaSignOut().subscribe(() => {
this.sessionService.signOut().subscribe(() => {
this.checkoutStep = 'giftContactPayment'
this.fireAnalyticsEvents('contact', 'payment')
// Remove initialLoadComplete session storage. Used on src/common/components/contactInfo/contactInfo.component.js
Expand Down
4 changes: 2 additions & 2 deletions src/app/branded/branded-checkout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ describe('branded checkout', () => {
})

it('should set initial checkout step and call formatDonorDetails', () => {
jest.spyOn($ctrl.sessionService, 'oktaSignOut').mockReturnValue(Observable.of(''))
jest.spyOn($ctrl.sessionService, 'signOut').mockReturnValue(Observable.of(''))
jest.spyOn($ctrl, 'formatDonorDetails').mockImplementation(() => {})
$ctrl.$onInit()

expect($ctrl.sessionService.oktaSignOut).toHaveBeenCalled()
expect($ctrl.sessionService.signOut).toHaveBeenCalled()
expect($ctrl.code).toEqual('1234567')
expect($ctrl.tsysService.setDevice).toHaveBeenCalledWith('test-env')
expect($ctrl.checkoutStep).toEqual('giftContactPayment')
Expand Down
11 changes: 9 additions & 2 deletions src/app/main/main.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'angular-ui-router'
import '../../assets/scss/styles.scss'

import sessionService from 'common/services/session/session.service'
import sessionModalService from 'common/services/session/sessionModal.service'
import commonModule from 'common/common.module'
import cartComponent from '../cart/cart.component'
import checkoutComponent from '../checkout/checkout.component'
Expand All @@ -25,12 +26,17 @@ const componentName = 'main'

class MainController {
/* @ngInject */
constructor (sessionService) /* eslint-disable-line no-useless-constructor */ {
constructor (sessionService, sessionModalService) /* eslint-disable-line no-useless-constructor */ {
this.sessionService = sessionService
this.sessionModalService = sessionModalService
}

signOut () {
return this.sessionService.oktaSignOut()
return this.sessionService.signOut()
}

signInModal () {
this.sessionModalService.signIn()
}
}

Expand Down Expand Up @@ -101,6 +107,7 @@ export default angular
receiptsComponent.name,
brandedCheckoutComponent.name,
sessionService.name,
sessionModalService.name,
'ui.router'
])
.config(routingConfig)
Expand Down
4 changes: 2 additions & 2 deletions src/app/main/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ describe('main', function () {

describe('signOut', () => {
beforeEach(() => {
jest.spyOn(self.controller.sessionService, 'oktaSignOut').mockImplementation(() => Observable.of({}))
jest.spyOn(self.controller.sessionService, 'signOut').mockImplementation(() => Observable.of({}))
})

it('should call session sign out', () => {
self.controller.signOut()
expect(self.controller.sessionService.oktaSignOut).toHaveBeenCalled()
expect(self.controller.sessionService.signOut).toHaveBeenCalled()
})
})
})
1 change: 1 addition & 0 deletions src/app/main/main.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<li><a href="/branded-checkout.html">Branded Checkout</a></li>
<li><nav-cart-icon></nav-cart-icon></li>
<li><a href="" ng-click="$ctrl.signOut()">Sign Out</a></li>
<li><a href="" ng-click="$ctrl.signInModal()">Sign In Modal</a></li>
</ul>

<ui-view></ui-view>
2 changes: 1 addition & 1 deletion src/common/components/signInForm/signInForm.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SignInFormController {
signInWithOkta () {
this.isSigningIn = true
delete this.errorMessage
this.sessionService.oktaSignIn(this.lastPurchaseId).subscribe(() => {
this.sessionService.signIn(this.lastPurchaseId).subscribe(() => {
const $injector = this.$injector
if (!$injector.has('sessionService')) {
$injector.loadNewModules(['sessionService'])
Expand Down
6 changes: 3 additions & 3 deletions src/common/components/signInForm/signInForm.component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ describe('signInForm', function () {
let deferred
beforeEach(inject(function (_$q_) {
deferred = _$q_.defer()
jest.spyOn($ctrl.sessionService, 'oktaSignIn').mockImplementation(() => Observable.from(deferred.promise))
jest.spyOn($ctrl.sessionService, 'signIn').mockImplementation(() => Observable.from(deferred.promise))
$ctrl.signInWithOkta()
}))

it('calls sessionService oktaSignIn', () => {
it('calls sessionService signIn', () => {
expect($ctrl.isSigningIn).toEqual(true)
expect($ctrl.sessionService.oktaSignIn).toHaveBeenCalledWith(undefined)
expect($ctrl.sessionService.signIn).toHaveBeenCalledWith(undefined)
})

it('signs in successfully', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class signUpActivationModalController {
signInWithOkta () {
this.isSigningIn = true
delete this.errorMessage
this.sessionService.oktaSignIn(this.lastPurchaseId).subscribe(() => {
this.sessionService.signIn(this.lastPurchaseId).subscribe(() => {
this.onSuccess()
}, error => {
this.isSigningIn = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ describe('signUpActivationModal', function () {
let deferred
beforeEach(inject(function (_$q_) {
deferred = _$q_.defer()
jest.spyOn($ctrl.sessionService, 'oktaSignIn').mockImplementation(() => Observable.from(deferred.promise))
jest.spyOn($ctrl.sessionService, 'signIn').mockImplementation(() => Observable.from(deferred.promise))
$ctrl.signInWithOkta()
}))

it('calls sessionService oktaSignIn', () => {
it('calls sessionService signIn', () => {
expect($ctrl.isSigningIn).toEqual(true)
expect($ctrl.sessionService.oktaSignIn).toHaveBeenCalledWith(lastPurchaseId)
expect($ctrl.sessionService.signIn).toHaveBeenCalledWith(lastPurchaseId)
})

it('signs in successfully', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/services/api/cart.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class Cart {
if (total <= 0) {
return this.sessionService.oktaIsUserAuthenticated().mergeMap((isAuthenticated) => {
if (!isAuthenticated) return this._addItem(uri, data)
return this.sessionService.oktaSignOut(false).mergeMap(() => {
return this.sessionService.signOut(false).mergeMap(() => {
return this._addItem(uri, data)
})
})
Expand Down
6 changes: 3 additions & 3 deletions src/common/services/api/cart.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ describe('cart service', () => {
describe('with empty cart', () => {
beforeEach(() => {
jest.spyOn(self.cartService, 'getTotalQuantity').mockReturnValue(Observable.of(0))
jest.spyOn(self.cartService.sessionService, 'oktaSignOut').mockReturnValue(Observable.from([]))
jest.spyOn(self.cartService.sessionService, 'signOut').mockReturnValue(Observable.from([]))
})

it('should delete cookies and addItem to cart', () => {
Expand All @@ -263,15 +263,15 @@ describe('cart service', () => {
).respond(200)
self.cartService.addItem('items/crugive/<some id>', { amount: 50 }).subscribe()
expect(self.cartService.sessionService.oktaIsUserAuthenticated).toHaveBeenCalled()
expect(self.cartService.sessionService.oktaSignOut).not.toHaveBeenCalled()
expect(self.cartService.sessionService.signOut).not.toHaveBeenCalled()
self.$httpBackend.flush()
})

it('should redirect user to login and not run addItem to cart', () => {
jest.spyOn(self.cartService.sessionService, 'oktaIsUserAuthenticated').mockReturnValue(Observable.from([true]))
self.cartService.addItem('items/crugive/<some id>', { amount: 50 }).subscribe()
expect(self.cartService.sessionService.oktaIsUserAuthenticated).toHaveBeenCalled()
expect(self.cartService.sessionService.oktaSignOut).toHaveBeenCalled()
expect(self.cartService.sessionService.signOut).toHaveBeenCalled()
})
})
})
Expand Down
10 changes: 5 additions & 5 deletions src/common/services/session/session.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const session = /* @ngInject */ function ($cookies, $rootScope, $http, $timeout,
getRole: currentRole,
createAccount: createAccount,
handleOktaRedirect: handleOktaRedirect,
oktaSignIn: oktaSignIn,
oktaSignOut: oktaSignOut,
signIn: signIn,
signOut: signOut,
downgradeToGuest: downgradeToGuest,
getOktaUrl: getOktaUrl,
removeOktaRedirectIndicator: removeOktaRedirectIndicator,
Expand All @@ -88,14 +88,14 @@ const session = /* @ngInject */ function ($cookies, $rootScope, $http, $timeout,
if (authClient.isLoginRedirect()) {
return Observable.from(authClient.token.parseFromUrl().then((tokenResponse) => {
authClient.tokenManager.setTokens(tokenResponse.tokens)
return oktaSignIn(lastPurchaseId)
return signIn(lastPurchaseId)
}))
} else {
return Observable.of(false)
}
}

function oktaSignIn (lastPurchaseId) {
function signIn (lastPurchaseId) {
setOktaRedirecting()
return Observable.from(internalSignIn(lastPurchaseId))
.map((response) => response ? response.data : response)
Expand Down Expand Up @@ -279,7 +279,7 @@ const session = /* @ngInject */ function ($cookies, $rootScope, $http, $timeout,
return Observable.from(authClient.isAuthenticated())
}

function oktaSignOut (redirectHome = true) {
function signOut (redirectHome = true) {
return Observable.from(internalSignOut(redirectHome))
}

Expand Down
10 changes: 5 additions & 5 deletions src/common/services/session/session.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('session service', function () {
})


describe('oktaSignOut', () => {
describe('signOut', () => {
beforeEach(() => {
jest.spyOn(sessionService.authClient, 'revokeAccessToken')
jest.spyOn(sessionService.authClient, 'revokeRefreshToken')
Expand All @@ -180,7 +180,7 @@ describe('session service', function () {
$httpBackend.expectDELETE('https://give-stage2.cru.org/okta/logout')
.respond(200, {})
sessionService
.oktaSignOut()
.signOut()
.subscribe((response) => {
expect(response.data).toEqual({})
})
Expand All @@ -189,7 +189,7 @@ describe('session service', function () {

it('should revoke tokens & log user out of Okta', () => {
sessionService
.oktaSignOut()
.signOut()
.subscribe(() => {
expect(sessionService.authClient.revokeAccessToken).toHaveBeenCalled()
expect(sessionService.authClient.revokeRefreshToken).toHaveBeenCalled()
Expand All @@ -203,7 +203,7 @@ describe('session service', function () {
jest.spyOn(sessionService.authClient, 'revokeAccessToken').mockImplementationOnce(() => Promise.reject())
try {
sessionService
.oktaSignOut()
.signOut()
.subscribe(() => {
expect(sessionService.authClient.revokeAccessToken).toHaveBeenCalled()
expect(sessionService.authClient.revokeRefreshToken).not.toHaveBeenCalled()
Expand All @@ -216,7 +216,7 @@ describe('session service', function () {
});
})

describe('oktaSignIn & handleOktaRedirect', () => {
describe('signIn & handleOktaRedirect', () => {
it('should handle a successful login', done => {
sessionService.authClient.shouldSucceed()
sessionService.authClient.setupForRedirect()
Expand Down

0 comments on commit d41d50c

Please sign in to comment.