-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for authenticated content setServerToken (#432)
* Fix for InvalidTokenError when auth cookie is null. * Fix import and change future date to 1000 years * Remove check for old cookie
- Loading branch information
1 parent
3579948
commit 23cec48
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { serverSetToken } from './../../modules/authenticated-content/lib/authenticate' | ||
import { Store } from 'vuex-mock-store' | ||
|
||
describe('setServerToken', () => { | ||
const MockDate = require('mockdate') | ||
const validToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1NjMxNzA5NTcsImV4cCI6MTU2MzE3MTU1NywiZHJ1cGFsIjp7InVpZCI6IjY0OTIifX0.vEJHPrci2KBBowyRvtZot5vHCE8xFcy77bWU814BLEmrk0Zs3bvGVAgJ_SlW57uwlCbyYeSMwe8-uKqHzsrrYBugW55qvua-UfdgkJfwxeH32PXZlStVgoHsPu_BHQMpqwOh9pcH-2Lueiz-BxbT1DrYduC4R6zHBTcO-VLiW0swDPVtZHgPFWruGYgyHN8T2YWsn0ujBkLNOxD6-7FAEeY5W0X-yEHLXESjA15YDcfRebSIsvtKrZrLu21PTW9E0ql0zkLFSCip46js-f2BOc8V7jnSQM5XNwKHwrU3gtIKDhKptBQmdDLQ8KCkFhKkoyepEMoBsK_y5TWhZNOPlw' | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
it('should set isAuth to true when valid JWT is passed in cookie', () => { | ||
MockDate.set('2019-07-15T06:19:17+00:00') | ||
|
||
const store = new Store({ | ||
state: { | ||
tideAuthenticatedContent: { | ||
isAuthenticated: false | ||
} | ||
} | ||
}) | ||
|
||
serverSetToken(`authenticatedContent=${validToken};`, store) | ||
expect(store.dispatch).toHaveBeenCalledWith('tideAuthenticatedContent/setAuthenticated', true) | ||
}) | ||
|
||
it('should isAuth to false when an expired JWT is passed in cookie', () => { | ||
MockDate.set('3022-07-15T06:19:17+00:00') | ||
|
||
const store = new Store({ | ||
state: { | ||
tideAuthenticatedContent: { | ||
isAuthenticated: false | ||
} | ||
} | ||
}) | ||
|
||
serverSetToken(`authenticatedContent=${validToken};`, store) | ||
expect(store.dispatch).toHaveBeenCalledWith('tideAuthenticatedContent/setAuthenticated', false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10469,6 +10469,11 @@ [email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkd | |
dependencies: | ||
minimist "0.0.8" | ||
|
||
mockdate@^2.0.3: | ||
version "2.0.3" | ||
resolved "https://registry.yarnpkg.com/mockdate/-/mockdate-2.0.3.tgz#f4095e5eaea94c5f8b4e0e708f5d79fdff846a66" | ||
integrity sha512-/wRyr3grWk3tyk188qjZpeiiAfkAoDPEGqyerretomeeaH0D+pN9MCcedhAwrkxX3a216gp8CwPeQMHfLvrFpA== | ||
|
||
modify-values@^1.0.0: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022" | ||
|
@@ -15430,6 +15435,13 @@ vue@^2.2.4, vue@^2.5.17, vue@^2.6.10: | |
version "2.6.10" | ||
resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.10.tgz#a72b1a42a4d82a721ea438d1b6bf55e66195c637" | ||
|
||
vuex-mock-store@^0.0.7: | ||
version "0.0.7" | ||
resolved "https://registry.yarnpkg.com/vuex-mock-store/-/vuex-mock-store-0.0.7.tgz#b18c529bc48b23dc596fdf9e0739676ae16dd7d1" | ||
integrity sha512-Hd8q/lab+U/b0o0YvGvUWbxtrFbRTxwTMp+VL8qPQ1l2wmhJOMBwb086yil5dn1i2qLiF8Y5UtgKqCMcLzShKQ== | ||
dependencies: | ||
lodash.clonedeep "^4.5.0" | ||
|
||
vuex-persistedstate@^2.5.4: | ||
version "2.5.4" | ||
resolved "https://registry.yarnpkg.com/vuex-persistedstate/-/vuex-persistedstate-2.5.4.tgz#a19710ad7f9a08cea4e65fc585924d9fdac7384a" | ||
|