From 431e41a71194346f16c9efdfc3e2f221ad60d71a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 24 Mar 2021 15:11:18 -0500 Subject: [PATCH] Add tests for VERIFY_CREDENTIALS_SUCCESS --- app/soapbox/reducers/__tests__/auth-test.js | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/soapbox/reducers/__tests__/auth-test.js b/app/soapbox/reducers/__tests__/auth-test.js index 381a871a3..090f80868 100644 --- a/app/soapbox/reducers/__tests__/auth-test.js +++ b/app/soapbox/reducers/__tests__/auth-test.js @@ -3,6 +3,7 @@ import { Map as ImmutableMap, fromJS } from 'immutable'; import { AUTH_APP_CREATED, AUTH_LOGGED_IN, + VERIFY_CREDENTIALS_SUCCESS, VERIFY_CREDENTIALS_FAIL, } from 'soapbox/actions/auth'; @@ -59,6 +60,42 @@ describe('auth reducer', () => { }); }); + describe('VERIFY_CREDENTIALS_SUCCESS', () => { + it('should import the user', () => { + const action = { + type: VERIFY_CREDENTIALS_SUCCESS, + token: 'ABCDEFG', + account: { id: '1234' }, + }; + + const expected = fromJS({ + '1234': { id: '1234', access_token: 'ABCDEFG' }, + }); + + const result = reducer(undefined, action); + expect(result.get('users')).toEqual(expected); + }); + + it('should set the account in the token', () => { + const action = { + type: VERIFY_CREDENTIALS_SUCCESS, + token: 'ABCDEFG', + account: { id: '1234' }, + }; + + const state = fromJS({ + tokens: { 'ABCDEFG': { token_type: 'Bearer', access_token: 'ABCDEFG' } }, + }); + + const expected = fromJS({ + 'ABCDEFG': { token_type: 'Bearer', access_token: 'ABCDEFG', account: '1234' }, + }); + + const result = reducer(state, action); + expect(result.get('tokens')).toEqual(expected); + }); + }); + describe('VERIFY_CREDENTIALS_FAIL', () => { it('should delete the failed token', () => { const state = fromJS({