Giter VIP home page Giter VIP logo

syncano-test's Introduction

@eyedea/syncano-test

Test solution for syncano socket based on @eyedea/syncano.

npm version license

Install

Install package in your socket directory:

$ npm install -D @eyedea/syncano-test

It is recommended to install this package as dev dependency, otherwise a lot of unnecessary packages will be deployed with socket.

Usage

  1. Create __tests__ directory in your socket. Add __tests__/tsconfig.json with the following content:
{
  "compilerOptions": {
    "lib": ["ES2015"]
  }
}
  1. Create your test file __tests__/ENDPOINT-NAME.test.js
import {run, stub, createSyncanoCoreMock} from '@eyedea/syncano'

describe('SOCKET/ENDPOINT-NAME', () => {
  it('should not fail', async () => {
    const meta = {user: undefined}
    const args = {id: 1}
    const mocks = createSyncanoCoreMock({
      data: {
        entity: {
          create: stub().resolves(args)
          fields: stub().fn({
            with: stub().fn({
              findOrFail: stub().resolves(args)
            })
          })
        }
      }
    })
    const result = await run('ENDPOINT-NAME', {args, meta}, {mocks})
    expect(result).toHaveProperty('data.id', args.id)
    expect(result).toHaveProperty('code', 200)
  })
})

License

MIT © Eyedea AS

syncano-test's People

Contributors

idered avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

syncano-test's Issues

Add support for dot notation mocks

const mock = createSyncanoCoreMock()
mock('user.findOrFail', stub().resolves())
mock('data.agreement.orderBy.where.list', stub().resolves([]))

Invalidate Core stub

In case like this on each iteration there should be created new Core stub with new data

it.each(validBookings)('should return valid data', async booking => {
    const mocks = createSyncanoCoreMock({
      endpoint: {
        get: stub().resolves({inOrganization: true}),
      },
      user: {
        findOrFail: stub().resolves({
          hubUserKey: 'xyz',
        }),
      },
      data: {
        resource: {
          find: resourceStub,
          where: stub().fn({
            firstOrFail: resourceStub,
          }),
        },
        booking: {
          fields: stub().fn({
            create: bookingStub,
          }),
          where: stub().fn({
            list: bookingWhereListStub,
          }),
        },
      },
    })

    const result = await run('create', {args: booking, meta}, {mocks})
    expect(result.code).toEqual(200)
  })

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.