Skip to content
Merged
Show file tree
Hide file tree
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
217 changes: 217 additions & 0 deletions test/sanity-check/api/asset-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
import path from 'path'
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader, writeDownloadedFile } from '../utility/fileOperations/readwrite'
import { contentstackClient } from '../utility/ContentstackClient.js'

var client = {}

var folderUID = ''
var assetUID = ''
var publishAssetUID = ''
var assetURL = ''
describe('Assets api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})

it('should asset Upload ', done => {
const asset = {
upload: path.join(__dirname, '../mock/customUpload.html'),
title: 'customasset',
description: 'Custom Asset Desc',
tags: ['Custom']
}
makeAsset().create(asset)
.then((asset) => {
assetUID = asset.uid
assetURL = asset.url
expect(asset.uid).to.be.not.equal(null)
expect(asset.url).to.be.not.equal(null)
expect(asset.filename).to.be.equal('customUpload.html')
expect(asset.title).to.be.equal('customasset')
expect(asset.description).to.be.equal('Custom Asset Desc')
expect(asset.content_type).to.be.equal('text/html')
done()
})
.catch(done)
})

it('should download asset from URL.', done => {
makeAsset().download({ url: assetURL, responseType: 'stream' })
.then((response) => {
writeDownloadedFile(response, 'asset1')
done()
}).catch(done)
})
it('should download asset from fetch details ', done => {
makeAsset(assetUID).fetch()
.then((asset) => asset.download({ responseType: 'stream' }))
.then((response) => {
writeDownloadedFile(response, 'asset2')
done()
}).catch(done)
})

it('should create folder ', done => {
makeAsset().folder().create({ asset: { name: 'Sample Folder' } })
.then((asset) => {
folderUID = asset.uid
expect(asset.uid).to.be.not.equal(null)
expect(asset.name).to.be.equal('Sample Folder')
expect(asset.is_dir).to.be.equal(true)
done()
})
.catch(done)
})

it('should asset Upload in folder', done => {
const asset = {
upload: path.join(__dirname, '../mock/customUpload.html'),
title: 'customasset in Folder',
description: 'Custom Asset Desc in Folder',
parent_uid: folderUID,
tags: 'folder'
}
makeAsset().create(asset)
.then((asset) => {
publishAssetUID = asset.uid
expect(asset.uid).to.be.not.equal(null)
expect(asset.url).to.be.not.equal(null)
expect(asset.filename).to.be.equal('customUpload.html')
expect(asset.title).to.be.equal('customasset in Folder')
expect(asset.description).to.be.equal('Custom Asset Desc in Folder')
expect(asset.content_type).to.be.equal('text/html')
expect(asset.parent_uid).to.be.equal(folderUID)
done()
})
.catch(done)
})

it('should asset Upload in folder with contenttype', done => {
const asset = {
upload: path.join(__dirname, '../mock/berries.jfif'),
title: 'customasset2 in Folder',
description: 'Custom Asset Desc in Folder',
parent_uid: folderUID,
tags: 'folder',
content_type: 'image/jpeg'
}
makeAsset().create(asset)
.then((asset) => {
publishAssetUID = asset.uid
expect(asset.uid).to.be.not.equal(null)
expect(asset.url).to.be.not.equal(null)
expect(asset.filename).to.be.equal('berries.jfif')
expect(asset.title).to.be.equal('customasset2 in Folder')
expect(asset.description).to.be.equal('Custom Asset Desc in Folder')
expect(asset.content_type).to.be.equal('image/jpeg')
expect(asset.parent_uid).to.be.equal(folderUID)
done()
})
.catch(done)
})
it('should replace asset ', done => {
const asset = {
upload: path.join(__dirname, '../mock/upload.html')
}
makeAsset(assetUID)
.replace(asset)
.then((asset) => {
expect(asset.uid).to.be.equal(assetUID)
expect(asset.filename).to.be.equal('upload.html')
expect(asset.content_type).to.be.equal('text/html')
done()
})
.catch(done)
})

it('should fetch and Update asset details', done => {
makeAsset(assetUID)
.fetch()
.then((asset) => {
asset.title = 'Update title'
asset.description = 'Update description'
delete asset.ACL
return asset.update()
})
.then((asset) => {
expect(asset.uid).to.be.equal(assetUID)
expect(asset.title).to.be.equal('Update title')
expect(asset.description).to.be.equal('Update description')
done()
})
.catch(done)
})

it('should publish Asset', done => {
makeAsset(publishAssetUID)
.publish({ publishDetails: {
locales: ['hi-in', 'en-us'],
environments: ['development']
} })
.then((data) => {
expect(data.notice).to.be.equal('Asset sent for publishing.')
done()
})
.catch(done)
})

it('should unpublish Asset', done => {
makeAsset(publishAssetUID)
.unpublish({ publishDetails: {
locales: ['hi-in', 'en-us'],
environments: ['development']
} })
.then((data) => {
expect(data.notice).to.be.equal('Asset sent for unpublishing.')
done()
})
.catch(done)
})

it('should delete asset', done => {
makeAsset(assetUID)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Asset deleted successfully.')
done()
})
.catch(done)
})

it('should query to fetch all asset', done => {
makeAsset()
.query()
.find()
.then((collection) => {
collection.items.forEach((asset) => {
expect(asset.uid).to.be.not.equal(null)
expect(asset.title).to.be.not.equal(null)
expect(asset.description).to.be.not.equal(null)
})
done()
})
.catch(done)
})

it('should query to fetch title match asset', done => {
makeAsset()
.query({ query: { title: 'Update title' } })
.find()
.then((collection) => {
collection.items.forEach((asset) => {
expect(asset.uid).to.be.not.equal(null)
expect(asset.title).to.be.equal('Update title')
expect(asset.description).to.be.equal('Update description')
})
done()
})
.catch(done)
})
})

function makeAsset (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).asset(uid)
}
2 changes: 1 addition & 1 deletion test/sanity-check/api/contentType-delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Content Type delete api Test', () => {
client = contentstackClient(user.authtoken)
})

it('Content Type delete', done => {
it('should content Type delete', done => {
makeContentType(multiPageCT.content_type.uid)
.delete().then((data) => {
expect(data.notice).to.be.equal('Content Type deleted successfully.')
Expand Down
16 changes: 8 additions & 8 deletions test/sanity-check/api/contentType-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Content Type api Test', () => {
client = contentstackClient(user.authtoken)
})

it('Create Single page ContentType Schema', done => {
it('should create Single page ContentType Schema', done => {
makeContentType()
.create(singlepageCT)
.then((contentType) => {
Expand All @@ -26,7 +26,7 @@ describe('Content Type api Test', () => {
.catch(done)
})

it('Create Multi page ContentType Schema', done => {
it('should create Multi page ContentType Schema', done => {
makeContentType()
.create(multiPageCT)
.then((contentType) => {
Expand All @@ -38,7 +38,7 @@ describe('Content Type api Test', () => {
.catch(done)
})

it('Get all ContentType', done => {
it('should get all ContentType', done => {
makeContentType()
.query()
.find()
Expand All @@ -53,7 +53,7 @@ describe('Content Type api Test', () => {
.catch(done)
})

it('Query ContentType title', done => {
it('should query ContentType title', done => {
makeContentType()
.query({ query: { title: singlepageCT.content_type.title } })
.find()
Expand All @@ -70,7 +70,7 @@ describe('Content Type api Test', () => {
.catch(done)
})

it('Fetch ContentType from uid', done => {
it('should fetch ContentType from uid', done => {
makeContentType(multiPageCT.content_type.uid)
.fetch()
.then((contentType) => {
Expand All @@ -81,7 +81,7 @@ describe('Content Type api Test', () => {
.catch(done)
})

it('Fetch and Update ContentType schema', done => {
it('should fetch and Update ContentType schema', done => {
makeContentType(multiPageCTUid)
.fetch()
.then((contentType) => {
Expand All @@ -95,7 +95,7 @@ describe('Content Type api Test', () => {
.catch(done)
})

it('Import content type', done => {
it('should import content type', done => {
makeContentType().import({
content_type: path.join(__dirname, '../mock/contentType.json')
})
Expand All @@ -107,7 +107,7 @@ describe('Content Type api Test', () => {
.catch(done)
})

it('Delete ContentTypes', done => {
it('should delete ContentTypes', done => {
makeContentType(importCTUid)
.delete()
.then((contentType) => {
Expand Down
Loading