How to use the fetchr.registerService function in fetchr

To help you get started, we’ve selected a few fetchr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github recruit-tech / redux-pluto / src / shared / redux / __test__ / agreedSample.js View on Github external
/* eslint-disable no-undefined */
import { test } from "eater/runner";
import Fetchr from "fetchr";
import assert from "power-assert";
import { getText } from "../modules/agreedSample";
import { createStore } from "./lib/storeUtils";

let needFailure = null;
Fetchr.registerService({
  name: "agreedSample",
  read(req, resource, params, config, cb) {
    return needFailure
      ? cb(new Error("failure"))
      : cb(needFailure, { text: "Hello world" });
  }
});

const store = createStore({ cookie: {} });

test("agreedSample: getText success", () => {
  store.dispatch(getText()).then(() => {
    assert.deepEqual(store.getState().page.agreedSample, {
      text: "Hello world",
      loading: false,
      loaded: true
github recruit-tech / redux-pluto / src / shared / redux / __test__ / auth.login.js View on Github external
/* eslint-disable no-undefined */
import Fetchr from "fetchr";
import { test } from "eater/runner";
import assert from "power-assert";
import { ACCESS_TOKEN_AUDIENCE_NAME } from "server/services/AccessToken";
import { login } from "shared/redux/modules/auth";
import { createStore, createWithSignedStore } from "./lib/storeUtils";

/**
 * mock accessToken service
 */
Fetchr.registerService({
  name: "accessToken",
  create(req, resource, params, body, config, cb) {
    if (params && params.username === "s") {
      return void cb(new Error("username is short"));
    }

    cb(null, null);
  }
});

test("auth: login success username scott", () => {
  const loginAction = login("scott", "tiger");
  createWithSignedStore("scott", ACCESS_TOKEN_AUDIENCE_NAME, {}).then(store => {
    store.dispatch(loginAction).then(() => {
      assert.deepEqual(store.getState().app.auth, {
        login: true,
github recruit-tech / redux-pluto / src / shared / redux / __test__ / style.searchStyle.js View on Github external
/* eslint-disable no-undefined, callback-return */
import Fetchr from "fetchr";
import { test } from "eater/runner";
import assert from "power-assert";
import Immutable from "seamless-immutable";
import { INITIAL_STATE, searchStyle } from "../modules/style";
import { createStore } from "./lib/storeUtils";

let needFailure = false;
Fetchr.registerService({
  name: "style",
  read(req, resource, params, config, cb) {
    return needFailure
      ? cb(new Error("failure"))
      : cb(null, { results_available: "10", style: ["foo", "bar"] });
  }
});

test("style: searchStyle success", () => {
  const searchStyleAction = searchStyle({ query: "foo" });
  const initialState = Immutable({ page: { style: INITIAL_STATE } });
  const store = createStore({
    initialState
  });
  store.dispatch(searchStyleAction).then(() => {
    const state = store.getState().page.style;
github recruit-tech / redux-pluto / src / shared / redux / __test__ / auth.logout.js View on Github external
/* eslint-disable no-undefined */
import Fetchr from "fetchr";
import { test } from "eater/runner";
import assert from "power-assert";
import { ACCESS_TOKEN_AUDIENCE_NAME } from "server/services/AccessToken";
import { login, logout } from "shared/redux/modules/auth";
import { createWithSignedStore } from "./lib/storeUtils";

/**
 * mock accessToken service
 */
Fetchr.registerService({
  name: "accessToken",
  create(req, resource, params, body, config, cb) {
    cb(null, null);
  },

  delete(req, resource, params, config, cb) {
    cb(null, null);
  }
});

test("auth: logout success", done => {
  const logoutAction = logout();
  createWithSignedStore("scott", ACCESS_TOKEN_AUDIENCE_NAME, {}).then(store => {
    store.dispatch(logoutAction).then(() => {
      assert.deepEqual(store.getState().app.auth, {
        login: false,
github recruit-tech / redux-pluto / src / shared / redux / __test__ / auth.checkLogin.js View on Github external
/* eslint-disable no-undefined */
import { test } from "eater/runner";
import assert from "power-assert";
import Fetchr from "fetchr";
import { ACCESS_TOKEN_AUDIENCE_NAME } from "server/services/AccessToken";
import { checkLogin } from "shared/redux/modules/auth";
import { createWithSignedStore, createStore } from "./lib/storeUtils";

/**
 * mock accessToken service
 */
Fetchr.registerService({
  name: "accessToken",
  create(req, resource, params, body, config, cb) {
    cb(null, null);
  },

  delete(req, resource, params, config, cb) {
    cb(null, null);
  }
});

test("auth: checkLogin success", () => {
  const checkLoginAction = checkLogin();
  createWithSignedStore("scott", ACCESS_TOKEN_AUDIENCE_NAME, {}).then(store => {
    store.dispatch(checkLoginAction).then(() => {
      assert.deepEqual(store.getState().app.auth, {
        login: true,
github recruit-tech / redux-pluto / src / server / middlewares / apiGateway.ts View on Github external
Object.values(services).forEach((Service: any) => {
    const service = new Service(config);
    debug(`Registering sevice: ${service.name}`);
    Fetchr.registerService(makeServiceAdapter(service, config.auth.secret));
    requestAdapter(service, app, config);
  });

fetchr

Fetchr augments Flux applications by allowing Flux stores to be used on server and client to fetch data

Unrecognized
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis