onFeathersService
Subscribes to mocked server socket events to work as FeathersJS CRUD service.
server.onFeathersService(name, fixtureStore, [options])
Subscribes to mocked server socket events according to FeathersJS protocol. Uses fixture store [can-fixture.Store] as a resource storage.
var fixtureStore = fixture.store([
{id: 1, title: 'One'},
{id: 2, title: 'Two'},
{id: 3, title: 'Three'}
], new canSet.Algebra({}));
server.onFeathersService("messages", fixtureStore})
Use
Instantiate fixture store by calling store and provide FeathersJS service name:
const fixtureStore = fixture.store( [
{ _id: 1, title: "One" },
{ _id: 2, title: "Two" },
{ _id: 3, title: "Three" }
], new canSet.Algebra( canSet.props.id( "_id" ) ) );
mockServer.onFeathersService( "messages", fixtureStore, { id: "_id" } );
This will emulate FeathersJS server CRUD service.
Now from Feathers client app you can do:
// Import dependencies:
import io from "socket.io-client";
import feathers from "feathers/client";
import feathersSocketio from "feathers-socketio/client";
import hooks from "feathers-hooks";
// Configure Feathers client app:
const socket = io( "http://api.my-feathers-server.com" );
const app = feathers()
.configure( hooks() )
.configure( feathersSocketio( socket ) );
// Create client Feathers service:
const messagesService = app.service( "messages" );
// Test:
messagesService.get( 1 ).then( function( data ) {
assert.deepEqual( data, { id: 1, title: "One" }, "get should receive an item" );
} );