Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelberg-okta committed Mar 20, 2018
1 parent 5c246b6 commit be58ab3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/okta-vue/src/Auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,46 @@ import AuthJS from '@okta/okta-auth-js'
import { createLocalVue } from '@vue/test-utils'
import { default as Auth } from './Auth'

const mockAuthJsInstance = {userAgent: 'foo'}
const pkg = require('../package.json')

jest.mock('@okta/okta-auth-js')

const mockAuthJsInstance = {
userAgent: 'foo',
token: {
getWithRedirect: jest.fn()
}
}

AuthJS.mockImplementation(() => {
return mockAuthJsInstance
})

const localVue = createLocalVue()

describe('Auth', () => {
test('is a Vue plugin', () => {
expect(Auth.install).toBeTruthy()
})
test('sets the right user agent on AuthJS', () => {
const expectedUserAgent = `${pkg.name}/${pkg.version} foo`
const localVue = createLocalVue()
localVue.use(Auth, {
issuer: '1',
client_id: '2',
redirect_uri: '3'
})
expect(mockAuthJsInstance.userAgent).toMatch(expectedUserAgent)
})
test('sets the context for the $auth plugin', () => {
test('sets the right scope and response_type when redirecting to Okta', () => {
const localVue = createLocalVue()
localVue.use(Auth, {
issuer: '1',
client_id: '2',
redirect_uri: '3',
response_type: 'a b'
scope: 'foo bar',
response_type: 'token'
})
expect(localVue.prototype.$auth).toBeDefined()
localVue.prototype.$auth.loginRedirect()
const mockCallValues = mockAuthJsInstance.token.getWithRedirect.mock.calls[0][0]
expect(mockCallValues.responseType).toEqual(expect.arrayContaining(['token']))
expect(mockCallValues.scopes).toEqual(expect.arrayContaining(['foo', 'bar']))
})
})

0 comments on commit be58ab3

Please sign in to comment.