UNPKG

@vtex/client-cms

Version:

A client to fetch data from VTEX CMS.

56 lines (42 loc) 1.63 kB
import type { Locator } from '../src/index' import ClientCMS from '../src/index' const clientCMS = new ClientCMS({ workspace: 'master', tenant: 'storeframework', }) test('Should create a client and return right options', () => { const options = clientCMS.getOptions() expect(options).toEqual({ workspace: 'master', tenant: 'storeframework', builder: 'faststore', host: '', }) }) test('Should create the right ApiUrl', () => { const apiUrl = clientCMS.getApiUrl() expect(apiUrl).toEqual('https://master--storeframework.myvtex.com') }) test('Should return right all content type Ids', async () => { const contentTypeIds = await clientCMS.getAllContentTypeIds() expect(contentTypeIds).toContain('plp') expect(Array.isArray(contentTypeIds)).toBe(true) }) test('Should return right CMS pages content types', async () => { const CMSPages = await clientCMS.getCMSPagesByContentType('plp') expect(CMSPages.data).toHaveLength(CMSPages.totalItems) expect(Array.isArray(CMSPages.data)).toBe(true) expect(Array.isArray(CMSPages.data[0].sections)).toBe(true) }) test('Should return right CMS page', async () => { const paginatedCMSPages = await clientCMS.getCMSPagesByContentType('plp') const locator: Locator = { contentType: paginatedCMSPages.data[0].type, documentId: paginatedCMSPages.data[0].id, versionId: paginatedCMSPages.data[0].versionId!, } const CMSPage = await clientCMS.getCMSPage(locator) expect(Array.isArray(CMSPage.sections)).toBe(true) expect(locator.contentType).toEqual(CMSPage.type) expect(locator.documentId).toEqual(CMSPage.id) })