Skip to content

revert these tests out as these are yet to be validated #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 131 additions & 141 deletions test/sanity-check/api/bulkOperation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { describe, it, setup } from 'mocha'
import { jsonReader } from '../../sanity-check/utility/fileOperations/readwrite'
import { contentstackClient } from '../../sanity-check/utility/ContentstackClient'
import { singlepageCT, multiPageCT } from '../mock/content-type.js'
import { createManagementToken } from '../mock/managementToken.js'
// import { createManagementToken } from '../mock/managementToken.js'
import dotenv from 'dotenv'
dotenv.config()

let client = {}
let clientWithManagementToken = {}
// let clientWithManagementToken = {}
let entryUid1 = ''
let assetUid1 = ''
let entryUid2 = ''
let assetUid2 = ''
let jobId1 = ''
let jobId2 = ''
let jobId3 = ''
let tokenUidDev = ''
let tokenUid = ''
// let jobId1 = ''
// let jobId2 = ''
// let jobId3 = ''
// let tokenUidDev = ''
// let tokenUid = ''

describe('BulkOperation api test', () => {
setup(() => {
Expand All @@ -31,23 +31,23 @@ describe('BulkOperation api test', () => {
entryUid2 = entryRead2.uid
assetUid2 = assetRead2.uid
client = contentstackClient(user.authtoken)
clientWithManagementToken = contentstackClient()
// clientWithManagementToken = contentstackClient()
})

it('should create a Management Token for get job status', done => {
makeManagementToken()
.create(createManagementToken)
.then((token) => {
tokenUidDev = token.token
tokenUid = token.uid
expect(token.name).to.be.equal(createManagementToken.token.name)
expect(token.description).to.be.equal(createManagementToken.token.description)
expect(token.scope[0].module).to.be.equal(createManagementToken.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
done()
})
.catch(done)
})
// it('should create a Management Token for get job status', done => {
// makeManagementToken()
// .create(createManagementToken)
// .then((token) => {
// tokenUidDev = token.token
// tokenUid = token.uid
// expect(token.name).to.be.equal(createManagementToken.token.name)
// expect(token.description).to.be.equal(createManagementToken.token.description)
// expect(token.scope[0].module).to.be.equal(createManagementToken.token.scope[0].module)
// expect(token.uid).to.be.not.equal(null)
// done()
// })
// .catch(done)
// })

it('should publish one entry when publishDetails of an entry is passed', done => {
const publishDetails = {
Expand All @@ -70,7 +70,7 @@ describe('BulkOperation api test', () => {
.then((response) => {
expect(response.notice).to.not.equal(undefined)
expect(response.job_id).to.not.equal(undefined)
jobId1 = response.job_id
// jobId1 = response.job_id
done()
})
.catch(done)
Expand All @@ -95,7 +95,7 @@ describe('BulkOperation api test', () => {
.then((response) => {
expect(response.notice).to.not.equal(undefined)
expect(response.job_id).to.not.equal(undefined)
jobId2 = response.job_id
// jobId2 = response.job_id
done()
})
.catch(done)
Expand Down Expand Up @@ -135,138 +135,128 @@ describe('BulkOperation api test', () => {
.then((response) => {
expect(response.notice).to.not.equal(undefined)
expect(response.job_id).to.not.equal(undefined)
jobId3 = response.job_id
// jobId3 = response.job_id
done()
})
.catch(done)
})

it('should get job status for the first publish job', done => {
doBulkOperationWithManagementToken(tokenUidDev)
.jobStatus({ job_id: jobId1, api_version: '3.2' })
.then((response) => {
expect(response).to.not.equal(undefined)
expect(response.uid).to.not.equal(undefined)
expect(response.status).to.not.equal(undefined)
expect(response.action).to.not.equal(undefined)
expect(response.summary).to.not.equal(undefined)
expect(response.body).to.not.equal(undefined)
done()
})
.catch((error) => {
console.error('Job status error:', error)
done(error)
})
})
// it('should get job status for the first publish job', done => {
// doBulkOperationWithManagementToken(tokenUidDev)
// .jobStatus({ job_id: jobId1, api_version: '3.2' })
// .then((response) => {
// expect(response).to.not.equal(undefined)
// expect(response.uid).to.not.equal(undefined)
// expect(response.status).to.not.equal(undefined)
// expect(response.action).to.not.equal(undefined)
// expect(response.summary).to.not.equal(undefined)
// expect(response.body).to.not.equal(undefined)
// done()
// })
// .catch((error) => {
// console.error('Job status error:', error)
// done(error)
// })
// })

it('should validate detailed job status response structure', done => {
doBulkOperationWithManagementToken(tokenUidDev)
.jobStatus({ job_id: jobId1, api_version: '3.2' })
.then((response) => {
expect(response).to.not.equal(undefined)
// Validate main job properties
expect(response.uid).to.not.equal(undefined)
expect(response.api_key).to.not.equal(undefined)
expect(response.status).to.not.equal(undefined)
// it('should validate detailed job status response structure', done => {
// doBulkOperationWithManagementToken(tokenUidDev)
// .jobStatus({ job_id: jobId1, api_version: '3.2' })
// .then((response) => {
// expect(response).to.not.equal(undefined)
// // Validate main job properties
// expect(response.uid).to.not.equal(undefined)
// expect(response.api_key).to.not.equal(undefined)
// expect(response.status).to.not.equal(undefined)

// Validate body structure
expect(response.body).to.not.equal(undefined)
expect(response.body.locales).to.be.an('array')
expect(response.body.environments).to.be.an('array')
// Validate summary structure
expect(response.summary).to.not.equal(undefined)
done()
})
.catch((error) => {
console.error('Detailed job status error:', error)
done(error)
})
})
// // Validate body structure
// expect(response.body).to.not.equal(undefined)
// expect(response.body.locales).to.be.an('array')
// expect(response.body.environments).to.be.an('array')
// // Validate summary structure
// expect(response.summary).to.not.equal(undefined)
// done()
// })
// .catch((error) => {
// console.error('Detailed job status error:', error)
// done(error)
// })
// })

it('should get job status for the second publish job', done => {
doBulkOperationWithManagementToken(tokenUidDev)
.jobStatus({ job_id: jobId2, api_version: '3.2' })
.then((response) => {
expect(response).to.not.equal(undefined)
expect(response.uid).to.not.equal(undefined)
expect(response.status).to.not.equal(undefined)
expect(response.action).to.not.equal(undefined)
expect(response.summary).to.not.equal(undefined)
expect(response.body).to.not.equal(undefined)
done()
})
.catch(done)
})
// it('should get job status for the second publish job', done => {
// doBulkOperationWithManagementToken(tokenUidDev)
// .jobStatus({ job_id: jobId2, api_version: '3.2' })
// .then((response) => {
// expect(response).to.not.equal(undefined)
// expect(response.uid).to.not.equal(undefined)
// expect(response.status).to.not.equal(undefined)
// expect(response.action).to.not.equal(undefined)
// expect(response.summary).to.not.equal(undefined)
// expect(response.body).to.not.equal(undefined)
// done()
// })
// .catch(done)
// })

it('should get job status for the third publish job', done => {
doBulkOperationWithManagementToken(tokenUidDev)
.jobStatus({ job_id: jobId3, api_version: '3.2' })
.then((response) => {
expect(response).to.not.equal(undefined)
expect(response.uid).to.not.equal(undefined)
expect(response.status).to.not.equal(undefined)
expect(response.action).to.not.equal(undefined)
expect(response.summary).to.not.equal(undefined)
expect(response.body).to.not.equal(undefined)
done()
})
.catch(done)
})
// it('should get job status for the third publish job', done => {
// doBulkOperationWithManagementToken(tokenUidDev)
// .jobStatus({ job_id: jobId3, api_version: '3.2' })
// .then((response) => {
// expect(response).to.not.equal(undefined)
// expect(response.uid).to.not.equal(undefined)
// expect(response.status).to.not.equal(undefined)
// expect(response.action).to.not.equal(undefined)
// expect(response.summary).to.not.equal(undefined)
// expect(response.body).to.not.equal(undefined)
// done()
// })
// .catch(done)
// })

it('should get job status with bulk_version parameter', done => {
doBulkOperationWithManagementToken(tokenUidDev)
.jobStatus({ job_id: jobId1, bulk_version: 'v3', api_version: '3.2' })
.then((response) => {
expect(response).to.not.equal(undefined)
expect(response.uid).to.not.equal(undefined)
expect(response.status).to.not.equal(undefined)
expect(response.action).to.not.equal(undefined)
expect(response.summary).to.not.equal(undefined)
expect(response.body).to.not.equal(undefined)
done()
})
.catch(done)
})
// it('should get job status with bulk_version parameter', done => {
// doBulkOperationWithManagementToken(tokenUidDev)
// .jobStatus({ job_id: jobId1, bulk_version: 'v3', api_version: '3.2' })
// .then((response) => {
// expect(response).to.not.equal(undefined)
// expect(response.uid).to.not.equal(undefined)
// expect(response.status).to.not.equal(undefined)
// expect(response.action).to.not.equal(undefined)
// expect(response.summary).to.not.equal(undefined)
// expect(response.body).to.not.equal(undefined)
// done()
// })
// .catch(done)
// })

it('should test job status endpoint accessibility', done => {
doBulkOperationWithManagementToken(tokenUidDev)
.jobStatus({ job_id: 'test-job-id', api_version: '3.2' })
.then((response) => {
done()
})
.catch((error) => {
console.log('Job status endpoint error (expected for invalid job ID):', error.message)
// This is expected to fail with invalid job ID, but should not be an auth error
if (error.message && (error.message.includes('authentication') || error.message.includes('401'))) {
done(error)
} else {
done() // Expected error for invalid job ID
}
})
})
// it('should test job status endpoint accessibility', done => {
// doBulkOperationWithManagementToken(tokenUidDev)
// .jobStatus({ job_id: 'test-job-id', api_version: '3.2' })
// .then((response) => {
// done()
// })
// .catch((error) => {
// console.log('Job status endpoint error (expected for invalid job ID):', error.message)
// // This is expected to fail with invalid job ID, but should not be an auth error
// if (error.message && (error.message.includes('authentication') || error.message.includes('401'))) {
// done(error)
// } else {
// done() // Expected error for invalid job ID
// }
// })
// })

it('should delete a Management Token', done => {
makeManagementToken(tokenUid)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Management Token deleted successfully.')
done()
})
.catch(done)
})
// it('should delete a Management Token', done => {
// makeManagementToken(tokenUid)
// .delete()
// .then((data) => {
// expect(data.notice).to.be.equal('Management Token deleted successfully.')
// done()
// })
// .catch(done)
// })
})

function doBulkOperation (uid = null) {
// @ts-ignore-next-line secret-detection
return client.stack({ api_key: process.env.API_KEY }).bulkOperation()
}

function doBulkOperationWithManagementToken (tokenUidDev) {
// @ts-ignore-next-line secret-detection
return clientWithManagementToken.stack({ api_key: process.env.API_KEY, management_token: tokenUidDev }).bulkOperation()
}

function makeManagementToken (uid = null) {
// @ts-ignore-next-line secret-detection
return client.stack({ api_key: process.env.API_KEY }).managementToken(uid)
}
Loading