|
| 1 | +import { expect } from 'chai' |
| 2 | +import { describe, it, setup } from 'mocha' |
| 3 | +import { jsonReader } from '../utility/fileOperations/readwrite' |
| 4 | +import { createDeliveryToken3 } from '../mock/deliveryToken.js' |
| 5 | +import { contentstackClient } from '../utility/ContentstackClient.js' |
| 6 | +import dotenv from 'dotenv' |
| 7 | + |
| 8 | +dotenv.config(); |
| 9 | +let client = {}; |
| 10 | + |
| 11 | +let tokenUID = ""; |
| 12 | +describe("Preview Token api Test", () => { |
| 13 | + setup(() => { |
| 14 | + const user = jsonReader("loggedinuser.json"); |
| 15 | + client = contentstackClient(user.authtoken); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should add a Delivery Token for development", (done) => { |
| 19 | + makeDeliveryToken() |
| 20 | + .create(createDeliveryToken3) |
| 21 | + .then((token) => { |
| 22 | + tokenUID = token.uid |
| 23 | + expect(token.name).to.be.equal(createDeliveryToken3.token.name); |
| 24 | + expect(token.description).to.be.equal( |
| 25 | + createDeliveryToken3.token.description |
| 26 | + ); |
| 27 | + expect(token.scope[0].environments[0].name).to.be.equal( |
| 28 | + createDeliveryToken3.token.scope[0].environments[0] |
| 29 | + ); |
| 30 | + expect(token.scope[0].module).to.be.equal( |
| 31 | + createDeliveryToken3.token.scope[0].module |
| 32 | + ); |
| 33 | + expect(token.uid).to.be.not.equal(null); |
| 34 | + expect(token.preview_token).to.be.not.equal(null); |
| 35 | + done(); |
| 36 | + }) |
| 37 | + .catch(done); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should add a Preview Token", (done) => { |
| 41 | + makePreviewToken(tokenUID) |
| 42 | + .create() |
| 43 | + .then((token) => { |
| 44 | + expect(token.name).to.be.equal(createDeliveryToken3.token.name); |
| 45 | + expect(token.description).to.be.equal( |
| 46 | + createDeliveryToken3.token.description |
| 47 | + ); |
| 48 | + expect(token.scope[0].environments[0].name).to.be.equal( |
| 49 | + createDeliveryToken3.token.scope[0].environments[0] |
| 50 | + ); |
| 51 | + expect(token.scope[0].module).to.be.equal( |
| 52 | + createDeliveryToken3.token.scope[0].module |
| 53 | + ); |
| 54 | + expect(token.uid).to.be.not.equal(null); |
| 55 | + expect(token.preview_token).to.be.not.equal(null); |
| 56 | + done(); |
| 57 | + }) |
| 58 | + .catch(done); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should delete a Preview Token from uid", (done) => { |
| 62 | + makePreviewToken(tokenUID) |
| 63 | + .delete() |
| 64 | + .then((data) => { |
| 65 | + expect(data.notice).to.be.equal("Preview token deleted successfully."); |
| 66 | + done(); |
| 67 | + }) |
| 68 | + .catch(done); |
| 69 | + }); |
| 70 | + |
| 71 | + it("should delete a Delivery Token from uid", (done) => { |
| 72 | + makeDeliveryToken(tokenUID) |
| 73 | + .delete() |
| 74 | + .then((data) => { |
| 75 | + expect(data.notice).to.be.equal("Delivery Token deleted successfully."); |
| 76 | + done(); |
| 77 | + }) |
| 78 | + .catch(done); |
| 79 | + }); |
| 80 | +}); |
| 81 | + |
| 82 | +function makePreviewToken(uid = null) { |
| 83 | + return client |
| 84 | + .stack({ api_key: process.env.API_KEY }) |
| 85 | + .deliveryToken(uid) |
| 86 | + .previewToken(); |
| 87 | +} |
| 88 | + |
| 89 | +function makeDeliveryToken(uid = null) { |
| 90 | + return client.stack({ api_key: process.env.API_KEY }).deliveryToken(uid); |
| 91 | +} |
0 commit comments