import * as ssr from '../../../vue-apollo-ssr' describe('ssr states', () => { function buildClient(cache) { return { cache: { extract() { return cache }, }, } } const defaultClient = buildClient({ foo: 'hiya!', }) const otherClient = buildClient({ foo: 'bar', }) const clients = { defaultClient, profile: defaultClient, other: otherClient, } describe('serializeStates', () => { it('safely serializes by default', () => { const safe = '{"defaultClient":{"foo":"\\u003Calert\\u003Ehiya!\\u003C\\u002Falert\\u003E"},"profile":{"foo":"\\u003Calert\\u003Ehiya!\\u003C\\u002Falert\\u003E"},"other":{"foo":"bar"}}' const serialized = ssr.serializeStates(clients) expect(serialized).not.toMatch('hiya!') expect(serialized).toMatch(safe) }) it('allows option to use raw JSON stringify', () => { const unsafe = '{"defaultClient":{"foo":"hiya!"},"profile":{"foo":"hiya!"},"other":{"foo":"bar"}}' expect(ssr.serializeStates(clients, { useUnsafeSerializer: true })).toMatch(unsafe) }) }) describe('getStates', () => { it('exports provider clients to object', () => { expect(ssr.getStates(clients)).toMatchObject({ defaultClient: { foo: 'hiya!' }, profile: { foo: 'hiya!' }, other: { foo: 'bar' }, }) }) }) describe('exportStates', () => { it('sets attachTo and globalName equal to serializedstates', () => { const string = ssr.exportStates(clients, { globalName: 'NUXT', attachTo: 'global' }) expect(string).toMatch(/^global\.NUXT/) }) }) })