|
| 1 | +import { expect } from 'chai' |
| 2 | +import { describe, it, setup } from 'mocha' |
| 3 | +import { jsonReader } from '../utility/fileOperations/readwrite' |
| 4 | +import { contentstackClient } from '../utility/ContentstackClient.js' |
| 5 | + |
| 6 | +var client = {} |
| 7 | +var stack = {} |
| 8 | + |
| 9 | +describe('BulkOperation api test', () => { |
| 10 | + setup(() => { |
| 11 | + const user = jsonReader('loggedinuser.json') |
| 12 | + stack = jsonReader('stack.json') |
| 13 | + client = contentstackClient(user.authtoken) |
| 14 | + }) |
| 15 | + |
| 16 | + it('should publish one entry when publishDetails of an entry is passed', done => { |
| 17 | + const publishDetails = { |
| 18 | + entries: [ |
| 19 | + { |
| 20 | + uid: "blte6542a9aac484405", |
| 21 | + content_type: "bye", |
| 22 | + version: 1, |
| 23 | + locale: "en-us" |
| 24 | + } |
| 25 | + ], |
| 26 | + locales: [ |
| 27 | + "en-us" |
| 28 | + ], |
| 29 | + environments: [ |
| 30 | + "dev" |
| 31 | + ] |
| 32 | + } |
| 33 | + doBulkOperation() |
| 34 | + .publish({details:publishDetails, api_version:'3.2'}) |
| 35 | + .then((response) => { |
| 36 | + expect(response.notice).to.not.equal(undefined) |
| 37 | + expect(response.job_id).to.not.equal(undefined) |
| 38 | + done() |
| 39 | + }) |
| 40 | + .catch(done) |
| 41 | + }) |
| 42 | + |
| 43 | + it('should publish one asset when publishDetails of an asset is passed', done => { |
| 44 | + const publishDetails = { |
| 45 | + assets: [ |
| 46 | + { |
| 47 | + uid: "blt9f8e5aa45ac36455" |
| 48 | + } |
| 49 | + ], |
| 50 | + locales: [ |
| 51 | + "en-us" |
| 52 | + ], |
| 53 | + environments: [ |
| 54 | + "dev" |
| 55 | + ] |
| 56 | + } |
| 57 | + doBulkOperation() |
| 58 | + .publish({details:publishDetails, api_version:'3.2'}) |
| 59 | + .then((response) => { |
| 60 | + expect(response.notice).to.not.equal(undefined) |
| 61 | + expect(response.job_id).to.not.equal(undefined) |
| 62 | + done() |
| 63 | + }) |
| 64 | + .catch(done) |
| 65 | + }) |
| 66 | + |
| 67 | + it('should publish multiple entries assets when publishDetails of entries and assets are passed', done => { |
| 68 | + const publishDetails = { |
| 69 | + entries: [ |
| 70 | + { |
| 71 | + uid: "blt077157784a170bab", |
| 72 | + content_type: "bye", |
| 73 | + version: 1, |
| 74 | + locale: "en-us" |
| 75 | + }, { |
| 76 | + uid: "blta519039712ca2b8a", |
| 77 | + content_type: "bye", |
| 78 | + version: 1, |
| 79 | + locale: "en-us" |
| 80 | + } |
| 81 | + ], |
| 82 | + assets: [ |
| 83 | + { |
| 84 | + uid: "blt9f8e5aa45ac36455" |
| 85 | + }, { |
| 86 | + uid: "blt3b097cc58475b0a3" |
| 87 | + } |
| 88 | + ], |
| 89 | + locales: [ |
| 90 | + "en-us" |
| 91 | + ], |
| 92 | + environments: [ |
| 93 | + "dev" |
| 94 | + ] |
| 95 | + } |
| 96 | + doBulkOperation() |
| 97 | + .publish({details:publishDetails, api_version:'3.2'}) |
| 98 | + .then((response) => { |
| 99 | + expect(response.notice).to.not.equal(undefined) |
| 100 | + expect(response.job_id).to.not.equal(undefined) |
| 101 | + done() |
| 102 | + }) |
| 103 | + .catch(done) |
| 104 | + }) |
| 105 | +}) |
| 106 | + |
| 107 | +function doBulkOperation (uid = null) { |
| 108 | + return client.stack({ api_key: stack.api_key }).bulkOperation() |
| 109 | +} |
0 commit comments