mongodb-stitch
Version:
[](https://gitter.im/mongodb/stitch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
67 lines (57 loc) • 2.25 kB
JavaScript
const StitchMongoFixture = require('../fixtures/stitch_mongo_fixture');
import { buildAdminTestHarness, extractTestFixtureDataPoints } from '../testutil';
describe('Apps', ()=>{
let test = new StitchMongoFixture();
let th;
beforeAll(() => test.setup());
afterAll(() => test.teardown());
beforeEach(async() => {
const { apiKey, groupId, serverUrl } = extractTestFixtureDataPoints(test);
th = await buildAdminTestHarness(false, apiKey, groupId, serverUrl);
});
afterEach(async() => th.cleanup());
it('listing apps should return empty list', async() => {
let apps = await th.apps().list();
expect(apps).toEqual([]);
});
const testAppName = 'testapp';
it('can create an app successfully', async() => {
const app = await th.createApp(testAppName);
expect(app).toBeDefined();
expect(app.name).toEqual(testAppName);
});
it('newly created app should appear in list', async() => {
const app = await th.createApp(testAppName);
const apps = (await th.apps().list()).filter(x => x._id === app._id);
expect(apps).toHaveLength(1);
expect(apps[0]).toEqual(app);
});
it('can fetch an existing app', async() => {
const app = await th.createApp(testAppName);
const appFetched = await th.app().get();
expect(app).toEqual(appFetched);
});
it('can delete an app', async() => {
const app = await th.createApp(testAppName);
await th.appRemove();
th.testApp = undefined;
const apps = (await th.apps().list()).filter(x => x._id === app._id);
expect(apps).toHaveLength(0);
});
describe('when createApp is called with a specific product type', () => {
let app;
const otherProductTestAppName = 'atlas-app';
beforeEach(async() => {
app = await th.createApp(otherProductTestAppName, { product: 'atlas' });
});
it('should successfully create the app', () => {
expect(app).toBeDefined();
expect(app.name).toEqual(otherProductTestAppName);
});
it('should only display apps of a product type when the list function is called with that filter', async() => {
const apps = (await th.apps().list({ product: 'atlas' }));
expect(apps).toHaveLength(1);
expect(apps[0]).toEqual(app);
});
});
});