Mokker

The mock does not mock you

Andrei Fidelman

problem

// import ui from '../testServices/checkoutUI';

export const getUI = () => {
  return (dispatch) => {
    dispatch({ type: SHOPPING_CART_UI_FETCH });

    // setTimeout(() => {
    //   dispatch({
    //     payload: ui
    //   });
    // }, 3000);

    axios.get(url)
      .then((response) => {
        const { payload } = response.data;
    
        dispatch({ payload });
      });
  };
};
import ui from '../testServices/checkoutUI';

export const getUI = () => {
  return (dispatch) => {
    dispatch({ type: SHOPPING_CART_UI_FETCH });

    setTimeout(() => {
      dispatch({
        payload: ui
      });
    }, 3000);

    // axios.get(url)
    //   .then((response) => {
    //     const { payload } = response.data;
    // 
    //     dispatch({ payload });
    //   });
  };
};

Development

Production

problem

import { staticUI } from 'app.ws/checkoutUI';

export const createAC = (dev, prod) => {
  if (process.env.NODE_ENV === 'development';) {
    dev();
  } else {
    prod();
  }
};

const prod = () => {
    axios.get(url)
        .then((response) => {
            const { payload } = response.data;

           dispatch({ payload });  
        });
};

const dev = () => {
    setTimeout(() => {
        dispatch({
            payload: staticUI
        });
    }, 1500);
};

createAC(dev, prod);

problem

const config = require('../config');
const gulp = require('gulp');
const jsonServer = require('json-server');

const api = () => {
    const loginSuccess = {
      success: true
    };

    return { mailingSuccess };
};

function start(cb) {
    const app = jsonServer.create();
    const router = jsonServer.router(api());
    const middleware = jsonServer.defaults();
    app.use(middleware);
    app.use(router);
    const server = app.listen(config.API_PORT, () => {
        gutil.log(
            gutil.colors.green(`JSON Server is running…`),
            gutil.colors.gray(`http://localhost:${config.API_PORT}`)
        );
    });
}

gulp.task('api', start);


problem

motivation

  1. To have a server
  2. To create endpoints quickly
  3. To play with responses
  4. To have a documentation not breaking DRY

Demo time

Mokker

The mock does not mock you

Andrei Fidelman

Made with Slides.com