Skip to content

Commit 085cf8c

Browse files
committed
Restore husky hooks, commit entry/stack/content-type test updates
1 parent 8d5bc32 commit 085cf8c

File tree

3 files changed

+144
-1
lines changed

3 files changed

+144
-1
lines changed

test/sanity-check/api/entry-test.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,116 @@ describe('Entry API Tests', () => {
361361
})
362362
})
363363

364+
// ==========================================================================
365+
// MASTER COVERAGE: asset_fields, localize, publish (cases added with feature/fix)
366+
// ==========================================================================
367+
368+
describe('Entry asset_fields, localize and publish (master coverage)', () => {
369+
before(function () {
370+
if (!mediumCtReady) {
371+
console.log(' Skipping: Medium content type not available')
372+
this.skip()
373+
}
374+
})
375+
376+
it('should entry fetch with asset_fields parameter - single value', async function () {
377+
this.timeout(15000)
378+
const uid = testData.entries?.medium?.uid
379+
if (!uid) this.skip()
380+
const entry = await stack.contentType(mediumCtUid).entry(uid).fetch({ asset_fields: ['user_defined_fields'] })
381+
trackedExpect(entry.uid, 'Entry UID').toEqual(uid)
382+
})
383+
384+
it('should entry fetch with asset_fields parameter - multiple values', async function () {
385+
this.timeout(15000)
386+
const uid = testData.entries?.medium?.uid
387+
if (!uid) this.skip()
388+
const entry = await stack.contentType(mediumCtUid).entry(uid).fetch({ asset_fields: ['user_defined_fields', 'embedded', 'ai_suggested', 'visual_markups'] })
389+
trackedExpect(entry.uid, 'Entry UID').toEqual(uid)
390+
})
391+
392+
it('should localize entry with title update', async function () {
393+
this.timeout(15000)
394+
const uid = testData.entries?.medium?.uid
395+
if (!uid) this.skip()
396+
// Use a locale that exists on the dynamic stack (create if missing)
397+
const locales = await stack.locale().query().find()
398+
const items = locales.items || locales.locales || []
399+
const enAt = items.find(l => l.code === 'en-at')
400+
if (!enAt) {
401+
try {
402+
await stack.locale().create({
403+
locale: { code: 'en-at', name: 'English (Austria)', fallback_locale: 'en-us' }
404+
})
405+
} catch (e) {
406+
this.skip() // locale may already exist or stack doesn't support it
407+
return
408+
}
409+
}
410+
const entry = await stack.contentType(mediumCtUid).entry(uid).fetch()
411+
entry.title = 'Sample Entry in en-at'
412+
const response = await entry.update({ locale: 'en-at' })
413+
expect(response.title).to.equal('Sample Entry in en-at')
414+
expect(response.uid).to.be.a('string')
415+
expect(response.locale).to.equal('en-at')
416+
})
417+
418+
it('should get all Entry with asset_fields parameter - single value', async function () {
419+
this.timeout(15000)
420+
const collection = await stack.contentType(mediumCtUid).entry().query({ include_count: true, asset_fields: ['user_defined_fields'] }).find()
421+
expect(collection).to.be.an('object')
422+
if (collection.count !== undefined) {
423+
expect(collection.count).to.be.a('number')
424+
}
425+
expect(collection.items).to.be.an('array')
426+
collection.items.forEach((entry) => {
427+
expect(entry.uid).to.be.a('string')
428+
expect(entry.content_type_uid).to.equal(mediumCtUid)
429+
})
430+
})
431+
432+
it('should get all Entry with asset_fields parameter - multiple values', async function () {
433+
this.timeout(15000)
434+
const collection = await stack.contentType(mediumCtUid).entry().query({ include_count: true, asset_fields: ['user_defined_fields', 'embedded', 'ai_suggested', 'visual_markups'] }).find()
435+
expect(collection.items).to.be.an('array')
436+
collection.items.forEach((entry) => {
437+
expect(entry.uid).to.be.a('string')
438+
expect(entry.content_type_uid).to.equal(mediumCtUid)
439+
})
440+
})
441+
442+
it('should get all Entry with asset_fields parameter combined with other query params', async function () {
443+
this.timeout(15000)
444+
const collection = await stack.contentType(mediumCtUid).entry().query({
445+
include_count: true,
446+
include_content_type: true,
447+
asset_fields: ['user_defined_fields', 'embedded']
448+
}).find()
449+
expect(collection.items).to.be.an('array')
450+
collection.items.forEach((entry) => {
451+
expect(entry.uid).to.be.a('string')
452+
expect(entry.content_type_uid).to.equal(mediumCtUid)
453+
})
454+
})
455+
456+
it('should publish Entry', async function () {
457+
this.timeout(15000)
458+
const uid = testData.entries?.medium?.uid
459+
if (!uid) this.skip()
460+
// Use environment that exists on dynamic stack
461+
const envName = testData.environments?.development?.name || 'development'
462+
const entry = await stack.contentType(mediumCtUid).entry(uid)
463+
const response = await entry.publish({
464+
publishDetails: {
465+
locales: ['en-us'],
466+
environments: [envName]
467+
}
468+
})
469+
expect(response).to.be.an('object')
470+
trackedExpect(response.uid ?? response.entry_uid, 'Published entry').toBeA('string')
471+
})
472+
})
473+
364474
// ==========================================================================
365475
// ENTRY CRUD OPERATIONS
366476
// ==========================================================================

test/sanity-check/api/stack-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe('Stack API Tests', () => {
201201
expect(response.stack.collaborators || response.stack.users).to.be.an('array')
202202
}
203203
} catch (error) {
204-
console.log('Stack users not available:', error.errorMessage)
204+
console.log('Stack users not available:', error.errorMessage || error.message || 'unknown')
205205
}
206206
})
207207

test/sanity-check/mock/content-type.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,36 @@ export const singlepageCT = {
3232
},
3333
prevcreate: true
3434
}
35+
36+
/** Multi-page content type (for bulk operation tests from master). */
37+
export const multiPageCT = {
38+
content_type: {
39+
options: {
40+
is_page: true,
41+
singleton: false,
42+
title: 'title',
43+
sub_title: [],
44+
url_pattern: '/:title'
45+
},
46+
title: 'Multi page',
47+
uid: 'multi_page',
48+
schema: [
49+
{
50+
display_name: 'Title',
51+
uid: 'title',
52+
data_type: 'text',
53+
mandatory: true,
54+
unique: true,
55+
field_metadata: { _default: true }
56+
},
57+
{
58+
display_name: 'URL',
59+
uid: 'url',
60+
data_type: 'text',
61+
mandatory: false,
62+
field_metadata: { _default: true }
63+
}
64+
]
65+
},
66+
prevcreate: true
67+
}

0 commit comments

Comments
 (0)