Preload: call verifyCredentials after Mastodon preload to get the "source" parameter of the account
This commit is contained in:
parent
ca1b4ff73d
commit
96c2e42ebf
5 changed files with 27 additions and 2 deletions
|
@ -13,6 +13,12 @@ const setupMock = axios => {
|
|||
|
||||
export const staticClient = api.staticClient;
|
||||
|
||||
export const baseClient = (...params) => {
|
||||
const axios = api.baseClient(...params);
|
||||
setupMock(axios);
|
||||
return axios;
|
||||
};
|
||||
|
||||
export default (...params) => {
|
||||
const axios = api.default(...params);
|
||||
setupMock(axios);
|
||||
|
|
|
@ -2,14 +2,21 @@ import {
|
|||
MASTODON_PRELOAD_IMPORT,
|
||||
preloadMastodon,
|
||||
} from '../preload';
|
||||
import { VERIFY_CREDENTIALS_REQUEST } from '../auth';
|
||||
import { ACCOUNTS_IMPORT } from '../importer';
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { __stub } from 'soapbox/api';
|
||||
import { mockStore } from 'soapbox/test_helpers';
|
||||
|
||||
describe('preloadMastodon()', () => {
|
||||
it('creates the expected actions', () => {
|
||||
const data = require('soapbox/__fixtures__/mastodon_initial_state.json');
|
||||
|
||||
__stub(mock => {
|
||||
mock.onGet('/api/v1/accounts/verify_credentials')
|
||||
.reply(200, {});
|
||||
});
|
||||
|
||||
const store = mockStore(ImmutableMap());
|
||||
store.dispatch(preloadMastodon(data));
|
||||
const actions = store.getActions();
|
||||
|
@ -18,6 +25,11 @@ describe('preloadMastodon()', () => {
|
|||
expect(actions[0].accounts[0].username).toEqual('Gargron');
|
||||
expect(actions[0].accounts[1].username).toEqual('benis911');
|
||||
|
||||
expect(actions[1]).toEqual({ type: MASTODON_PRELOAD_IMPORT, data });
|
||||
expect(actions[1]).toEqual({
|
||||
type: VERIFY_CREDENTIALS_REQUEST,
|
||||
token: 'Nh15V9JWyY5Fshf2OJ_feNvOIkTV7YGVfEJFr0Y0D6Q',
|
||||
});
|
||||
|
||||
expect(actions[2]).toEqual({ type: MASTODON_PRELOAD_IMPORT, data });
|
||||
});
|
||||
});
|
||||
|
|
|
@ -143,7 +143,7 @@ export function verifyCredentials(token, accountUrl) {
|
|||
const baseURL = parseBaseURL(accountUrl);
|
||||
|
||||
return (dispatch, getState) => {
|
||||
dispatch({ type: VERIFY_CREDENTIALS_REQUEST });
|
||||
dispatch({ type: VERIFY_CREDENTIALS_REQUEST, token });
|
||||
|
||||
return baseClient(token, baseURL).get('/api/v1/accounts/verify_credentials').then(({ data: account }) => {
|
||||
dispatch(importFetchedAccount(account));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { mapValues } from 'lodash';
|
||||
import { importFetchedAccounts } from './importer';
|
||||
import { verifyCredentials } from './auth';
|
||||
|
||||
export const PLEROMA_PRELOAD_IMPORT = 'PLEROMA_PRELOAD_IMPORT';
|
||||
export const MASTODON_PRELOAD_IMPORT = 'MASTODON_PRELOAD_IMPORT';
|
||||
|
@ -52,7 +53,11 @@ export function preloadPleroma(data) {
|
|||
|
||||
export function preloadMastodon(data) {
|
||||
return (dispatch, getState) => {
|
||||
const { me, access_token } = data.meta;
|
||||
const { url } = data.accounts[me];
|
||||
|
||||
dispatch(importFetchedAccounts(Object.values(data.accounts)));
|
||||
dispatch(verifyCredentials(access_token, url));
|
||||
dispatch({ type: MASTODON_PRELOAD_IMPORT, data });
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
import { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS } from 'soapbox/actions/me';
|
||||
import { VERIFY_CREDENTIALS_SUCCESS } from 'soapbox/actions/auth';
|
||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||
|
||||
const initialState = ImmutableMap();
|
||||
|
@ -21,6 +22,7 @@ export default function accounts_meta(state = initialState, action) {
|
|||
switch(action.type) {
|
||||
case ME_FETCH_SUCCESS:
|
||||
case ME_PATCH_SUCCESS:
|
||||
case VERIFY_CREDENTIALS_SUCCESS:
|
||||
return importAccount(state, fromJS(action.me));
|
||||
default:
|
||||
return state;
|
||||
|
|
Loading…
Reference in a new issue