Skip to content

Instantly share code, notes, and snippets.

View LarryKarani's full-sized avatar
😀
Life is too short to write bad code

Larry karani LarryKarani

😀
Life is too short to write bad code
View GitHub Profile
import React from 'react';
import styled from 'styled-componets';
const Button = styled.button`
cursor: pointer;
background: transparent;
font-size: 16px;
border-radius: 3px;
color: palevioletred;
border: 2px solid palevioletred;
{ type: ADD_TODO_SUCCESS, payload: { item: 'Todo item' } }
{ type: ADD_TODO_FAILURE, payload: {error: 'Bad item'} }
import axios from 'axios';
import * as actions from './actions';
export const getTodos = () => (dispatch) => {
dispatch(actions.apiRequest());
axios.get('api/todos').then(res => {
dispatch(actions.getTodoSuccess(res.data));
return res;
})
.catch(error => {
// ACTION TYPES
export const API_REQUEST = 'API_REQUEST';
export const GET_TODO_SUCCESS = 'GET_TODO_SUCCESS';
export const GET_TODO_FAIL = 'GET_TODO_FAIL';
export const ADD_TODO_SUCCESS = 'ADD_TODO_SUCCESS';
export const ADD_TODO_FAIL = 'ADD_TODO_FAIL';
//ACTION CREATORS
export const apiRequestAction = () => ({
type: API_REQUEST
describe('post Todos actions', () => {
beforeEach(() => {
store.clearActions();
});
it('dispatches POST_TODO_SUCCESS after a successfull API requets', () => {
mock.onPost('api/todos').reply(201, { response: { item: 'item1' } })
store.dispatch(actions.getTodos()).then(() => {
let expectedActions = [
{ type: 'API_REQUEST' },
{ type: 'POST_TODOS_SUCCESS', payload: { item: 'item1' } }
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import * as actions from './actions';
const middleware = [thunk];
const mockStore = configureMockStore(middleware);
const mock = new MockAdapter(axios);
const store = mockStore();
from rest_framework.test import APIClient
from rest_framework import status
from django.urls import reverse
from ..models import Blog
client = APIClient()
class GetSingleBlogTest(TestCase):
""" Test module for GET single Blog API """