import { expect } from 'chai' import { Interphase } from '../src' import { ICreateInput, IDeleteInput, IMetafieldStorefrontVisibility, IMetafieldStorefrontVisibilities, IMetafieldStorefrontVisibilitiesResponse, IMetafieldStorefrontVisibilityCreateResponse, IDeletedMetafieldStorefrontVisibilityResponse } from '../src/contracts' const store = 'starship-furniture' const accessToken = 'e962314cf9c0b9e7fbf4a9cb78b256b8' describe('Interphase', function () { const interphase = new Interphase(store, accessToken) describe('create', function () { it('should create a metafieldVisibility', async function () { const data = await interphase.create({ input: { namespace: 'test_namespace', key: 'test_key', ownerType: 'PRODUCT' } }) expect(data.metafieldStorefrontVisibilityCreate.metafieldStorefrontVisibility).is.not.null }) }) describe('get', function () { it('should get all metafieldVisibilities', async function () { const data = await interphase.get() expect(data.metafieldStorefrontVisibilities.edges).is.not.null }) }) describe('delete', function () { it('should delete metafieldVisibility', async function () { await interphase.get() const nodeToDelete = interphase.metafieldStorefrontVisibilities.edges .find(({ node }) => { return node.key === 'test_key' && node.namespace === 'test_namespace' }) if (nodeToDelete) { const data = await interphase.delete({ id: nodeToDelete.node.id }) const deletedId = data.metafieldStorefrontVisibilityDelete.deletedMetafieldStorefrontVisibilityId expect(deletedId).equals(nodeToDelete.node.id) } else { console.error('Test Metafield is undefined') expect(nodeToDelete).is.undefined } }) }) }) describe('RechargeAdapter', async function () { const interphase = new Interphase(store, accessToken) describe('create all', function () { it('should create all Recharge metafieldVisibility', async function () { await interphase.Recharge.createAll() const matches: IMetafieldStorefrontVisibility[] = [] let allRechargeMetafieldsExposed = interphase.Recharge.rechargeKeys.every(key => { const match = interphase.metafieldStorefrontVisibilities.edges.find(({ node }) => { return node.key === key && node.namespace === 'subscriptions' }) if (match) { matches.push(match) } // type guard clause return match }) if (allRechargeMetafieldsExposed === false) { console.error('interphase', interphase.metafieldStorefrontVisibilities) console.error('allRechargeMetafieldsExposed matches', matches) } expect(allRechargeMetafieldsExposed).is.true }) }) })