Skip to content

Commit

Permalink
Added functional test for import endpoint in API v2
Browse files Browse the repository at this point in the history
no issue

- This change is a follow up to this bugfix #10299
- Added default export JSON to keep the state of db test suite intact
- Small typo fixe that noticed while debugging
  • Loading branch information
naz committed Jan 2, 2019
1 parent 8d6def1 commit 6797da5
Show file tree
Hide file tree
Showing 3 changed files with 2,681 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/server/api/v2/utils/serializers/output/db.js
Expand Up @@ -18,7 +18,7 @@ module.exports = {
},

importContent(response, apiConfig, frame) {
debug('exportContent');
debug('importContent');

// NOTE: response can contain 2 objects if images are imported
const problems = (response.length === 2)
Expand Down
37 changes: 37 additions & 0 deletions core/test/functional/api/v2/admin/db_spec.js
Expand Up @@ -84,6 +84,43 @@ describe('DB API', () => {
});
});

it('import should succeed with default content', () => {
return Promise.resolve()
.then(() => {
return request.delete(localUtils.API.getApiQuery('db/'))
.set('Origin', config.get('url'))
.set('Accept', 'application/json')
.expect(204);
})
.then(() => {
return request.post(localUtils.API.getApiQuery('db/'))
.set('Origin', config.get('url'))
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.attach('importfile', path.join(__dirname, '/../../../../utils/fixtures/export/default_export.json'))
.expect(200)
.then((res) => {
const jsonResponse = res.body;
should.exist(jsonResponse.db);
should.exist(jsonResponse.problems);
jsonResponse.problems.should.have.length(3);
});
})
.then(() => {
return request.get(localUtils.API.getApiQuery('posts/'))
.set('Origin', config.get('url'))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.then((res) => {
let jsonResponse = res.body;
let results = jsonResponse.posts;
jsonResponse.posts.should.have.length(7);
_.filter(results, {page: false, status: 'published'}).length.should.equal(7);
});
});
});

it('import should fail without file', () => {
return request.post(localUtils.API.getApiQuery('db/'))
.set('Origin', config.get('url'))
Expand Down

0 comments on commit 6797da5

Please sign in to comment.