UNPKG

paradigm-core

Version:
110 lines (87 loc) 2.5 kB
const { Migrations, OrganizationsPlugin, ApplicationsPlugin, UsersPlugin, TestHelpers: {MockHTTPServer}, } = require('structure-core') const pluginsList = require('../../helpers/plugins') const DocTestAPI = require('../../helpers/test-api-documents') const server = new MockHTTPServer(pluginsList) const docTestApi = new DocTestAPI(server) const orgTestApi = new OrganizationsPlugin.TestAPI(server) const appTestApi = new ApplicationsPlugin.TestAPI(server) const userTestApi = new UsersPlugin.TestAPI(server) const createOrgAndApp = async function() { const orgRes = await orgTestApi.create({ title: 'work it' }) const orgId = orgRes.body.pkg.id const appRes = await appTestApi.create(orgId, { desc: '', title: 'App 45', host: 'app45.com' }) const appId = appRes.body.pkg.id return {orgId, appId} } describe('Documents: Table', function() { before(function() { this.migration = new Migrations({ db: 'test', items: {tables: [{ action: 'create', table: 'digital_assets', indexes: [ 'applicationId', 'updatedAt' ] }]}, plugins: pluginsList }) return this.migration.process() }) afterEach(function() { return this.migration.purge() }) it('should show documents correct number of documents based on expand', async function() { const {orgId, appId} = await createOrgAndApp() const userRes = await userTestApi.create(orgId, appId, { organizationId: orgId, username: 'tom', email: 'voldemort@horcruxes.r.us', password: 'c4ntf1ndmyc4v3br0' }) const user = userRes.body.pkg await docTestApi.create(orgId, appId, { applicationId: appId, fields: [ { body: 'foo', label: 'title', type: 'text-input' }, ], mode: 'slideshow', organizationId: orgId, title: '26 diaries that Harry Potter never read', slug: '26-diaries', categoryIds: [], userId: user.id }) await docTestApi.create(orgId, appId, { applicationId: appId, mode: 'listacle', organizationId: orgId, title: '27 diaries that Harry Potter never read', slug: '27-diaries', categoryIds: [], userId: user.id }) const res = await docTestApi.getAll(orgId, appId, { expand: false }) expect(res.body.status).to.equal(200) expect(res.body.pkg.documents.length).to.equal(2) }) })