From 14649a3b537f8695960a628ebe69a9214eaf9d73 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 31 Mar 2021 08:38:59 +1100 Subject: [PATCH] Tweaked test suite --- README.md | 6 ++++-- test/index.js | 32 ++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6cf1dd2..c59a582 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ const sineQL = require('sineql'); const schema = require('./schema.js'); const queryHandler = require('./query-handler.js'); -//omit 'queryHandler', 'createHandler', 'updateHandler' or 'deleteHandler' to disable those methods +//omit 'createHandler', 'updateHandler' or 'deleteHandler' to disable those methods const sine = sineQL(schema, { queryHandler }, { debug: true }); //open the endpoint @@ -54,10 +54,12 @@ scalar Date type Book { String title Date published + Float score } type Author { String name + Boolean alive Book books } `; @@ -204,7 +206,7 @@ When using `update`, `match` will find all existing records and update those usi ``` update Book { match title "The Wind in the Willows" - set published "15 June 1908" + set published 1908 } ``` diff --git a/test/index.js b/test/index.js index db356a8..4d30af9 100644 --- a/test/index.js +++ b/test/index.js @@ -6,8 +6,26 @@ const Op = { const books = { findAll: async args => { let arr = [ - { id: 1, title: 'The Wind in the Willows', published: '1908-06-15', score: 0.9 }, - { id: 2, title: 'The Fart in the Fronds', published: null, score: 0.45 } + { id: 1, title: 'Outlander', published: '1991' }, + { id: 2, title: 'Dragonfly in Amber', published: '1992' }, + { id: 3, title: 'Voyager', published: '1993' }, + { id: 4, title: 'Drums of Autumn', published: '1996' }, + { id: 5, title: 'The Fiery Cross', published: '2000' }, //Incorrect, the correct publish date is 2001 + { id: 6, title: 'The Breath of Snow and Ashes', published: '2005' }, + { id: 7, title: 'An Echo in the Bone', published: '2009' }, + { id: 8, title: 'Written in my Own Heart\'s Blood', published: '2014' }, + { id: 9, title: 'Go Tell the Bees That I Am Gone', published: null }, + + { id: 10, title: 'The Forest of Silence', published: '2000' }, + { id: 11, title: 'The Lake of Tears', published: '2000' }, + { id: 12, title: 'The City of Rats', published: '2000' }, + { id: 13, title: 'The Shifting Sands', published: '2000' }, + { id: 14, title: 'Dread Mountain', published: '2000' }, + { id: 15, title: 'The Maze of the Beast', published: '2000' }, + { id: 16, title: 'The Valley of the Lost', published: '2000' }, + { id: 17, title: 'Return to Del', published: '2000' }, + + { id: 18, title: 'The Wind in the Willows', published: '1908' }, ]; const { attributes, where } = args; @@ -42,9 +60,9 @@ const books = { const authors = { findAll: async args => { let arr = [ - { id: 1, name: 'Kenneth Grahame', books: [1], alive: false }, - { id: 2, name: 'Frank', books: [1, 2], alive: true }, - { id: 3, name: 'Betty', books: [2], alive: true } + { id: 1, name: 'Diana Gabaldon', books: [1, 2, 3, 4, 5, 6, 7, 8, 9] }, + { id: 2, name: 'Emily Rodda', books: [10, 11, 12, 13, 14, 15, 16, 17] }, + { id: 3, name: 'Kenneth Grahame', books: [18] } ]; const { attributes, where } = args; @@ -164,7 +182,7 @@ const queryHandlers = { const { typeName, ...fields } = query; //hack the id into the fields list (if it's not there already) - fields['id'] = fields['id'] || { typeName: 'Integer', scalar: true }; + fields['id'] = fields['id'] || { typeName: 'Integer', scalar: true }; //TODO: should this be automatic? //get the names of matched fields const matchedNames = Object.keys(fields).filter(field => fields[field].match); @@ -195,13 +213,11 @@ scalar Date type Book { String title Date published - Float score } type Author { String name Book books - Boolean alive } `;