Git Product home page Git Product logo

mirage-glue's Introduction

Ember Mirage factories are great for testing form data, however for pages that show models or lists of models and relationships, fixtures are better source than factories.

This library fetches server api endpoints you provide and writes or appends to mirage fixture files, saves significant amount of time and mental energy. It also removes the possibility of human error from manual fixture entries. Written for ember apps that uses RestAdapter.

  $ npm install -g mirage-glue

  $ mirage-glue localhost:4000/unicorns
  Data written to ./mirage/fixtures/unicorns.js (File size: 24 KB)
  Fixture file has 20 records (+20)

  $ mirage-glue localhost:4000/unicorns/55
  Data written to ./mirage/fixtures/unicorns.js (File size: 26 KB)
  Fixture file has 21 records (+1)

If you have an embedded hasOne() or belongsTo() relationship in your json API response the embedded record also gets created in its relevant fixture file!!

Example:

  $ mirage-glue localhost:4000/blog-posts
  Data written to ./mirage/fixtures/blog-posts.js (File size: 82 KB)
  Fixture file has 20 records (+20)
  appending data to file: mirage/fixtures/categories.js
  Data written to ./mirage/fixtures/categories.js (File size: 22 KB)
  Fixture file has 21 records (+1)

If you want to ignore nested parsing/fixture creation of relationships/objects you can provide --ignore-nesting option flag:

  $ mirage-glue localhost:4000/blog-posts --ignore-nesting
  Data written to ./mirage/fixtures/blog-posts.js (File size: 102 KB)
  Fixture file has 20 records (+20)

For routes that are hidden behind Bearer token authentication you can use the --token option flag:

  $ mirage-glue localhost:4000/me --token="Bearer aBcdDjtQQ5_u0Ke--yWfDIn9pZPXl8TYiQuJS-LKNUMP-efxi0lr2r1TLUS3Bttr"
  Data written to mirage/fixtures/users.js (File size: 0.89 KB)
  Fixture file has 1 records (+1)
  Data written to mirage/fixtures/phone-numbers.js (File size: 0.32 KB)
  Fixture file has 1 records (+1)
  Data written to mirage/fixtures/emails.js (File size: 0.40 KB)
  Fixture file has 1 records (+1)

Bonus: Using the same fixture data in Phoenix/Elixir tests:

When you provide an elixir-app=YourElixirAppName option, elixir fixture files are generated under ../backend/test/support/fixtures folder we gets loaded automatically by mix every time you run mix test:

  $ mirage-glue localhost:4000/hackers elixir-app=TheMatrix
  Data written to ./mirage/fixtures/hackers.js (File size: 17 KB)
  Fixture file has 6 records (+6)
  appending data to file: mirage/fixtures/human-subjects.js
  Data written to ./mirage/fixtures/human-subjects.js (File size: 68 KB)
  Fixture file has 8 records (+6)
  Data written to ../backend/test/support/fixtures/human_subject.ex (File size: 72 KB)
  Data written to ../backend/test/support/fixtures/hacker.ex (File size: 21 KB)

You can read the contents of the fixture files to understand how the use fixtures in Elixir tests. One big caveat of using fixtures in the backend is you might not have the referenced relationship of the fixture record thus foreign_key constraints prevent your fixtures from getting inserted to the database. The generated elixir fixture files use the fixturist elixir library to source referenced relationship from development database to the test database along with your fixture insertion.

mirage-glue's People

Contributors

izelnakri avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.