Gravity
  • Welcome to Gravity
  • Getting Started
  • Stack
  • Updates
  • Rules For AI
  • Troubleshooting
  • Gravity Server
    • Introduction
    • Installation
      • Install Node.js
      • Database Setup
      • Stripe Setup
      • Mailgun Setup
      • Install Gravity
    • Application Structure
    • REST API
      • API Scopes
      • Webhooks
    • Authentication
      • Email Verification
      • Social Sign On
      • Two-Factor Authentication
    • Authorization
      • Feature Access and Plan Restrictions
      • Permissions (Roles)
    • Config
    • Environment Variables
    • Database Queries
    • Handling Errors
    • Logging
    • Localization
    • Push Notifications
    • Email Notifications
    • User Feedback
    • User Onboarding
    • File Uploads
    • Billing
      • Seat Billing
      • Usage Billing
    • Free Accounts
    • CLI Toolbelt
    • Testing
    • AI Tools
    • Background Jobs
    • Deployment
  • Gravity Web
    • Introduction
    • Tailwind & SCSS
    • Routing
    • Events
    • Authentication
    • Localization
    • Hooks
      • useAPI
      • usePlans
      • usePermissions
    • Components
      • Alert
      • Animate
      • Avatar
      • Badge
      • Breadcrumb
      • Button
      • Calendar
      • Card
      • Chart
      • Checklist
      • Credit Card
      • Detail
      • Dialog
      • Dropdown
      • Feedback
      • Form
      • Grid
      • Header
      • Helper
      • Icon
      • Image
      • Layout
      • Link
      • List
      • Loader
      • Logo
      • Nav
      • Onboarding
      • Pagination
      • Popover
      • Progress
      • Row
      • Search
      • Separator
      • Sheet
      • Social
      • Stat
      • Table
      • Tabs
      • Toast (Notification)
      • Tooltip
      • User
      • View
    • Views
    • Handling Errors
    • Deployment
  • Gravity Native
    • Introduction
    • Prerequisites
    • Installation
    • App Context
    • Authentication
    • Localisation
    • External Linking
    • Handling Errors
    • Navigation
    • Config
    • Events
    • Views
    • Components
      • Badge
      • Blankslate
      • Button
      • Card
      • Chart
      • Form
      • Global
      • Grid
      • Icon
      • List
      • Logo
      • Message
      • Modal
      • Nav
      • Notification
      • Progress Bar
      • Search
      • Separator
      • Social
      • Stat
      • View
    • Push Notifications
    • Payments
    • Building Your App
  • Mission Control
    • Introduction
    • Installation
    • User Management
    • Feedback
    • Events
    • Logs
  • Website Template
    • Introduction
    • Environment Variables
    • Styling
    • Components
      • Article
      • Feature List
      • Footer
      • Hero
      • Layout
      • Pricing
      • Meta Data
      • Nav
      • Testimonial
    • Build and Deploy
Powered by GitBook
On this page

Was this helpful?

  1. Gravity Server

Testing

PreviousCLI ToolbeltNextAI Tools

Last updated 1 year ago

Was this helpful?

Gravity comes with a full suite of integration tests included to ensure your application functions as it should before releasing it.

Please set the SUPPORT_EMAIL variable in your before running tests as this email is used for testing.

// to start the tests, run:
gravity test

// or
npm test

The testing suite uses and , boilerplate tests are in the /test folder.

How Tests Work

A test calls the API endpoint and passes a data object. The response is then tested to ensure the correct status is returned and the returned data matches a specific format.

describe('POST /account', () => {
  it ('should create a new paid account', done => {

    config.account.paid.token = { id: 'tok_visa' };

    chai.request(server)
    .post('/api/account')
    .send(config.account.paid)
    .end((err, res) => {

      res.should.have.status(200);
      res.body.token.should.be.a('string');
      res.body.plan.should.eq(config.account.paid.plan);
      res.body.subscription.should.eq('active');
      process.env.token = 'Bearer ' + res.body.token;

      // cleanup
      delete config.account.paid.token;
      done();

    });
  }).timeout(config.timeout);
});

To add your tests, create a new test script and import it to the run.js file; use the example above as a template.

Tests are designed to work with email_verification enabled. If you modify the config, some tests may fail and need to be adjusted for your own requirements.

environment
mocha
chai