|
| 1 | +const defaultLogger = require('../lib/logger').default; |
| 2 | +const { ParseGraphQLSchema } = require('../lib/GraphQL/ParseGraphQLSchema'); |
| 3 | + |
| 4 | +describe('ParseGraphQLSchema', () => { |
| 5 | + let parseServer; |
| 6 | + let databaseController; |
| 7 | + let parseGraphQLSchema; |
| 8 | + |
| 9 | + beforeAll(async () => { |
| 10 | + parseServer = await global.reconfigureServer({ |
| 11 | + schemaCacheTTL: 100, |
| 12 | + }); |
| 13 | + databaseController = parseServer.config.databaseController; |
| 14 | + parseGraphQLSchema = new ParseGraphQLSchema( |
| 15 | + databaseController, |
| 16 | + defaultLogger |
| 17 | + ); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('constructor', () => { |
| 21 | + it('should require a databaseController and a log instance', () => { |
| 22 | + expect(() => new ParseGraphQLSchema()).toThrow( |
| 23 | + 'You must provide a databaseController instance!' |
| 24 | + ); |
| 25 | + expect(() => new ParseGraphQLSchema({})).toThrow( |
| 26 | + 'You must provide a log instance!' |
| 27 | + ); |
| 28 | + expect(() => new ParseGraphQLSchema({}, {})).not.toThrow(); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('load', () => { |
| 33 | + it('should cache schema', async () => { |
| 34 | + const graphQLSchema = await parseGraphQLSchema.load(); |
| 35 | + expect(graphQLSchema).toBe(await parseGraphQLSchema.load()); |
| 36 | + await new Promise(resolve => setTimeout(resolve, 200)); |
| 37 | + expect(graphQLSchema).toBe(await parseGraphQLSchema.load()); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should load a brand new GraphQL Schema if Parse Schema changes', async () => { |
| 41 | + await parseGraphQLSchema.load(); |
| 42 | + const parseClasses = parseGraphQLSchema.parseClasses; |
| 43 | + const parseClassesString = parseGraphQLSchema.parseClasses; |
| 44 | + const parseClassTypes = parseGraphQLSchema.parseClasses; |
| 45 | + const graphQLSchema = parseGraphQLSchema.parseClasses; |
| 46 | + const graphQLTypes = parseGraphQLSchema.parseClasses; |
| 47 | + const graphQLQueries = parseGraphQLSchema.parseClasses; |
| 48 | + const graphQLMutations = parseGraphQLSchema.parseClasses; |
| 49 | + const graphQLSubscriptions = parseGraphQLSchema.parseClasses; |
| 50 | + const newClassObject = new Parse.Object('NewClass'); |
| 51 | + await newClassObject.save(); |
| 52 | + await databaseController.schemaCache.clear(); |
| 53 | + await new Promise(resolve => setTimeout(resolve, 200)); |
| 54 | + await parseGraphQLSchema.load(); |
| 55 | + expect(parseClasses).not.toBe(parseGraphQLSchema.parseClasses); |
| 56 | + expect(parseClassesString).not.toBe(parseGraphQLSchema.parseClasses); |
| 57 | + expect(parseClassTypes).not.toBe(parseGraphQLSchema.parseClasses); |
| 58 | + expect(graphQLSchema).not.toBe(parseGraphQLSchema.parseClasses); |
| 59 | + expect(graphQLTypes).not.toBe(parseGraphQLSchema.parseClasses); |
| 60 | + expect(graphQLQueries).not.toBe(parseGraphQLSchema.parseClasses); |
| 61 | + expect(graphQLMutations).not.toBe(parseGraphQLSchema.parseClasses); |
| 62 | + expect(graphQLSubscriptions).not.toBe(parseGraphQLSchema.parseClasses); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
0 commit comments