Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* 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
/* 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,
/* 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;
/* 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,
/* 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,
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);
});