import { describe, beforeEach, afterEach, it, expect } from 'vitest'; import { checkUpdates, getIntrospectionChecksum } from '../check-updates'; import { Config } from '../app'; import { remoteApplication1 } from '../test/remote-graphql-1'; describe('update', () => { let remote1: any; beforeEach(async () => { remote1 = await remoteApplication1(); }); afterEach(async () => { return new Promise((resolve) => { remote1.server.close(resolve(null)); }); }); it('an update of a remote schema should give a new hash', async () => { const hash1 = await getIntrospectionChecksum('http://localhost:8008/graphql'); // This forces a new schema remote1.toggleSchema(); const hash2 = await getIntrospectionChecksum('http://localhost:8008/graphql'); expect(hash1).not.toEqual(hash2); }); it('an update of a remote schema should return true if the remote schema changes', async () => { const config: Config = { list: [{ name: 'foo', url: 'http://localhost:8008/graphql', prefix: 'foo_', }], allowedQueriesAndMutations: ['getFoo'], }; { // Run it once wo se fill upp the _version await checkUpdates(config); const updated = await checkUpdates(config); expect(updated).toEqual(false); } // This forces a new schema remote1.toggleSchema(); { const updated = await checkUpdates(config); expect(updated).toEqual(true); } }); it('an update of a remote schema should return true if the remote version changes', async () => { const config: Config = { list: [{ name: 'foo', url: 'http://localhost:8008/graphql', versionUrl: 'http://localhost:8008/version', prefix: 'foo_', }], allowedQueriesAndMutations: ['getFoo'], }; // Run it once wo se fill upp the _version await checkUpdates(config); { const updated = await checkUpdates(config); expect(updated).toEqual(false); } // This forces a new schema remote1.setVersion('2'); { const updated = await checkUpdates(config); expect(updated).toEqual(true); } }); it('a remote service that isnt live wont break everything', async () => { const config: Config = { list: [{ name: 'foo', url: 'http://localhost:8011/graphql', prefix: 'foo_', }], allowedQueriesAndMutations: ['getFoo'], }; { const updated = await checkUpdates(config); expect(updated).toEqual(true); } }); });