e2e test passing
This commit is contained in:
13
src/api.js
Normal file
13
src/api.js
Normal file
@ -0,0 +1,13 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const client = axios.create({
|
||||
baseURL: 'https://api.outsidein.dev/Sy0NsAyaS8uuURS1zyCDp3Fzxcpg25iw',
|
||||
});
|
||||
const api = {
|
||||
async loadRestaurants(){
|
||||
const response = await client.get('/restaurants');
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
export default api;
|
@ -1,7 +1,13 @@
|
||||
import { createStore, applyMiddleware } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
import rootReducer from './reducers';
|
||||
import api from '../api';
|
||||
|
||||
const store = createStore(rootReducer, applyMiddleware(thunk));
|
||||
const store = createStore(
|
||||
rootReducer,
|
||||
applyMiddleware(
|
||||
thunk.withExtraArgument(api),
|
||||
),
|
||||
);
|
||||
|
||||
export default store;
|
32
src/store/restaurants.spec.js
Normal file
32
src/store/restaurants.spec.js
Normal file
@ -0,0 +1,32 @@
|
||||
import { createStore, applyMiddleware } from "redux";
|
||||
import thunk from 'redux-thunk';
|
||||
import restaurantReducer from './restaurants/reducers';
|
||||
import { loadRestaurants } from "./restaurants/actions";
|
||||
|
||||
describe('restaurants', () => {
|
||||
describe('loadRestaurants action', () => {
|
||||
it('stores the restaurants', async () => {
|
||||
const records = [
|
||||
{id: 1, name: 'Sushi Place'},
|
||||
{id: 2, name: 'Pizza Place'}
|
||||
];
|
||||
|
||||
const api = {
|
||||
loadRestaurants: () => Promise.resolve(records),
|
||||
};
|
||||
const initialState = {
|
||||
records: [],
|
||||
};
|
||||
const store = createStore(
|
||||
restaurantReducer,
|
||||
initialState,
|
||||
applyMiddleware(
|
||||
thunk.withExtraArgument(api),
|
||||
),
|
||||
);
|
||||
await store.dispatch(loadRestaurants());
|
||||
|
||||
expect(store.getState().records).toEqual(records)
|
||||
});
|
||||
});
|
||||
});
|
@ -1 +1,11 @@
|
||||
export const loadRestaurants = () => () => {};
|
||||
export const STORE_RESTAURANTS = 'STORE_RESTAURANTS';
|
||||
|
||||
export const loadRestaurants = () => async (dispatch, getState, api) => {
|
||||
const records = await api.loadRestaurants();
|
||||
dispatch(storeRestaurants(records));
|
||||
};
|
||||
|
||||
const storeRestaurants = records => ({
|
||||
type: STORE_RESTAURANTS,
|
||||
records
|
||||
});
|
@ -1,7 +1,13 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import { STORE_RESTAURANTS } from './actions';
|
||||
|
||||
function records() {
|
||||
return[];
|
||||
function records(state = [], action) {
|
||||
switch(action.type) {
|
||||
case STORE_RESTAURANTS:
|
||||
return action.records;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export default combineReducers({
|
||||
|
Reference in New Issue
Block a user