|
| 1 | +import path from 'path' |
| 2 | +import { expect } from 'chai' |
| 3 | +import { describe, it, setup } from 'mocha' |
| 4 | +import { jsonReader } from '../utility/fileOperations/readwrite.js' |
| 5 | +import { singlepageCT, multiPageCT, schema } from '../mock/content-type.js' |
| 6 | +import { contentstackClient } from '../utility/ContentstackClient.js' |
| 7 | + |
| 8 | +let client = {} |
| 9 | +let multiPageCTUid = '' |
| 10 | +let importCTUid = '' |
| 11 | + |
| 12 | +describe('Content Type api Test', () => { |
| 13 | + setup(() => { |
| 14 | + const user = jsonReader('loggedinuser.json') |
| 15 | + client = contentstackClient(user.authtoken) |
| 16 | + }) |
| 17 | + |
| 18 | + it('Create Single page ContentType Schema', done => { |
| 19 | + makeContentType() |
| 20 | + .create(singlepageCT) |
| 21 | + .then((contentType) => { |
| 22 | + expect(contentType.uid).to.be.equal(singlepageCT.content_type.uid) |
| 23 | + expect(contentType.title).to.be.equal(singlepageCT.content_type.title) |
| 24 | + done() |
| 25 | + }) |
| 26 | + .catch(done) |
| 27 | + }) |
| 28 | + |
| 29 | + it('Create Multi page ContentType Schema', done => { |
| 30 | + makeContentType() |
| 31 | + .create(multiPageCT) |
| 32 | + .then((contentType) => { |
| 33 | + multiPageCTUid = contentType.uid |
| 34 | + expect(contentType.uid).to.be.equal(multiPageCT.content_type.uid) |
| 35 | + expect(contentType.title).to.be.equal(multiPageCT.content_type.title) |
| 36 | + done() |
| 37 | + }) |
| 38 | + .catch(done) |
| 39 | + }) |
| 40 | + |
| 41 | + it('Get all ContentType', done => { |
| 42 | + makeContentType() |
| 43 | + .query() |
| 44 | + .find() |
| 45 | + .then((response) => { |
| 46 | + response.items.forEach(contentType => { |
| 47 | + expect(contentType.uid).to.be.not.equal(null) |
| 48 | + expect(contentType.title).to.be.not.equal(null) |
| 49 | + expect(contentType.schema).to.be.not.equal(null) |
| 50 | + }) |
| 51 | + done() |
| 52 | + }) |
| 53 | + .catch(done) |
| 54 | + }) |
| 55 | + |
| 56 | + it('Query ContentType title', done => { |
| 57 | + makeContentType() |
| 58 | + .query({ query: { title: singlepageCT.content_type.title } }) |
| 59 | + .find() |
| 60 | + .then((response) => { |
| 61 | + response.items.forEach(contentType => { |
| 62 | + expect(contentType.uid).to.be.not.equal(null) |
| 63 | + expect(contentType.title).to.be.not.equal(null) |
| 64 | + expect(contentType.schema).to.be.not.equal(null) |
| 65 | + expect(contentType.uid).to.be.equal(singlepageCT.content_type.uid, 'UID not mathcing') |
| 66 | + expect(contentType.title).to.be.equal(singlepageCT.content_type.title, 'Title not mathcing') |
| 67 | + }) |
| 68 | + done() |
| 69 | + }) |
| 70 | + .catch(done) |
| 71 | + }) |
| 72 | + |
| 73 | + it('Fetch ContentType from uid', done => { |
| 74 | + makeContentType(multiPageCT.content_type.uid) |
| 75 | + .fetch() |
| 76 | + .then((contentType) => { |
| 77 | + expect(contentType.uid).to.be.equal(multiPageCT.content_type.uid) |
| 78 | + expect(contentType.title).to.be.equal(multiPageCT.content_type.title) |
| 79 | + done() |
| 80 | + }) |
| 81 | + .catch(done) |
| 82 | + }) |
| 83 | + |
| 84 | + it('Fetch and Update ContentType schema', done => { |
| 85 | + makeContentType(multiPageCTUid) |
| 86 | + .fetch() |
| 87 | + .then((contentType) => { |
| 88 | + contentType.schema = schema |
| 89 | + return contentType.update() |
| 90 | + }) |
| 91 | + .then((contentType) => { |
| 92 | + expect(contentType.schema.length).to.be.equal(6) |
| 93 | + done() |
| 94 | + }) |
| 95 | + .catch(done) |
| 96 | + }) |
| 97 | + |
| 98 | + it('Import content type', done => { |
| 99 | + makeContentType().import({ |
| 100 | + content_type: path.join(__dirname, '../mock/contentType.json') |
| 101 | + }) |
| 102 | + .then((response) => { |
| 103 | + importCTUid = response.uid |
| 104 | + expect(response.uid).to.be.not.equal(null) |
| 105 | + done() |
| 106 | + }) |
| 107 | + .catch(done) |
| 108 | + }) |
| 109 | + |
| 110 | + it('Delete ContentTypes', done => { |
| 111 | + makeContentType(importCTUid) |
| 112 | + .delete() |
| 113 | + .then((contentType) => { |
| 114 | + expect(contentType.notice).to.be.equal('Content Type deleted successfully.') |
| 115 | + done() |
| 116 | + }) |
| 117 | + .catch(done) |
| 118 | + }) |
| 119 | +}) |
| 120 | + |
| 121 | +function makeContentType (uid = null) { |
| 122 | + return client.stack({ api_key: process.env.API_KEY }).contentType(uid) |
| 123 | +} |
0 commit comments