2024-01-02 14:39:14 +00:00
/ * \
title : tests - sql - tiddler - store . js
type : application / javascript
tags : [ [ $ : / t a g s / t e s t - s p e c ] ]
Tests the SQL tiddler store
\ * /
( function ( ) {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict" ;
if ( $tw . node ) {
describe ( "SQL tiddler store" , function ( ) {
// Create and initialise the tiddler store
var SqlTiddlerStore = require ( "$:/plugins/tiddlywiki/multiwikiserver/sql-tiddler-store.js" ) . SqlTiddlerStore ;
2024-01-19 10:28:04 +00:00
const sqlTiddlerStore = new SqlTiddlerStore ( {
adminWiki : new $tw . Wiki ( )
} ) ;
2024-01-02 14:39:14 +00:00
sqlTiddlerStore . createTables ( ) ;
// Create bags and recipes
2024-01-05 10:58:07 +00:00
sqlTiddlerStore . createBag ( "bag-alpha" ) ;
sqlTiddlerStore . createBag ( "bag-beta" ) ;
sqlTiddlerStore . createBag ( "bag-gamma" ) ;
sqlTiddlerStore . createRecipe ( "recipe-rho" , [ "bag-alpha" , "bag-beta" ] ) ;
sqlTiddlerStore . createRecipe ( "recipe-sigma" , [ "bag-alpha" , "bag-gamma" ] ) ;
2024-01-05 15:40:39 +00:00
sqlTiddlerStore . createRecipe ( "recipe-tau" , [ "bag-alpha" ] ) ;
sqlTiddlerStore . createRecipe ( "recipe-upsilon" , [ "bag-alpha" , "bag-gamma" , "bag-beta" ] ) ;
2024-01-02 14:39:14 +00:00
// Tear down
afterAll ( function ( ) {
// Close the database
sqlTiddlerStore . close ( ) ;
} ) ;
// Run tests
it ( "should save and retrieve tiddlers" , function ( ) {
// Save tiddlers
2024-01-19 19:52:57 +00:00
sqlTiddlerStore . saveBagTiddler ( { title : "Another Tiddler" , text : "I'm in alpha" , tags : "one two three" } , "bag-alpha" ) ;
sqlTiddlerStore . saveBagTiddler ( { title : "Hello There" , text : "I'm in alpha as well" , tags : "one two three" } , "bag-alpha" ) ;
sqlTiddlerStore . saveBagTiddler ( { title : "Hello There" , text : "I'm in beta" , tags : "four five six" } , "bag-beta" ) ;
sqlTiddlerStore . saveBagTiddler ( { title : "Hello There" , text : "I'm in gamma" , tags : "seven eight nine" } , "bag-gamma" ) ;
2024-01-02 14:39:14 +00:00
// Verify what we've got
2024-01-20 20:22:46 +00:00
expect ( sqlTiddlerStore . getRecipeTiddlers ( "recipe-rho" ) ) . toEqual ( [
{ title : 'Another Tiddler' , bag _name : 'bag-alpha' } ,
{ title : 'Hello There' , bag _name : 'bag-beta' }
] ) ;
expect ( sqlTiddlerStore . getRecipeTiddlers ( "recipe-sigma" ) ) . toEqual ( [
{ title : 'Another Tiddler' , bag _name : 'bag-alpha' } ,
{ title : 'Hello There' , bag _name : 'bag-gamma' }
] ) ;
2024-01-19 20:35:47 +00:00
expect ( sqlTiddlerStore . getRecipeTiddler ( "Hello There" , "recipe-rho" ) . tiddler ) . toEqual ( { title : "Hello There" , text : "I'm in beta" , tags : "four five six" } ) ;
2024-01-19 19:33:58 +00:00
expect ( sqlTiddlerStore . getRecipeTiddler ( "Missing Tiddler" , "recipe-rho" ) ) . toEqual ( null ) ;
2024-01-19 20:35:47 +00:00
expect ( sqlTiddlerStore . getRecipeTiddler ( "Another Tiddler" , "recipe-rho" ) . tiddler ) . toEqual ( { title : "Another Tiddler" , text : "I'm in alpha" , tags : "one two three" } ) ;
expect ( sqlTiddlerStore . getRecipeTiddler ( "Hello There" , "recipe-sigma" ) . tiddler ) . toEqual ( { title : "Hello There" , text : "I'm in gamma" , tags : "seven eight nine" } ) ;
expect ( sqlTiddlerStore . getRecipeTiddler ( "Another Tiddler" , "recipe-sigma" ) . tiddler ) . toEqual ( { title : "Another Tiddler" , text : "I'm in alpha" , tags : "one two three" } ) ;
expect ( sqlTiddlerStore . getRecipeTiddler ( "Hello There" , "recipe-upsilon" ) . tiddler ) . toEqual ( { title : "Hello There" , text : "I'm in beta" , tags : "four five six" } ) ;
2024-01-03 16:27:13 +00:00
// Delete a tiddlers to ensure the underlying tiddler in the recipe shows through
2024-01-02 14:39:14 +00:00
sqlTiddlerStore . deleteTiddler ( "Hello There" , "bag-beta" ) ;
2024-01-20 20:22:46 +00:00
expect ( sqlTiddlerStore . getRecipeTiddlers ( "recipe-rho" ) ) . toEqual ( [
{ title : 'Another Tiddler' , bag _name : 'bag-alpha' } ,
{ title : 'Hello There' , bag _name : 'bag-alpha' }
] ) ;
expect ( sqlTiddlerStore . getRecipeTiddlers ( "recipe-sigma" ) ) . toEqual ( [
{ title : 'Another Tiddler' , bag _name : 'bag-alpha' } ,
{ title : 'Hello There' , bag _name : 'bag-gamma' }
] ) ;
2024-01-19 19:33:58 +00:00
expect ( sqlTiddlerStore . getRecipeTiddler ( "Hello There" , "recipe-beta" ) ) . toEqual ( null ) ;
2024-01-02 14:39:14 +00:00
sqlTiddlerStore . deleteTiddler ( "Another Tiddler" , "bag-alpha" ) ;
2024-01-20 20:22:46 +00:00
expect ( sqlTiddlerStore . getRecipeTiddlers ( "recipe-rho" ) ) . toEqual ( [ { title : 'Hello There' , bag _name : 'bag-alpha' } ] ) ;
expect ( sqlTiddlerStore . getRecipeTiddlers ( "recipe-sigma" ) ) . toEqual ( [ { title : 'Hello There' , bag _name : 'bag-gamma' } ] ) ;
2024-01-03 16:27:13 +00:00
// Save a recipe tiddler
sqlTiddlerStore . saveRecipeTiddler ( { title : "More" , text : "None" } , "recipe-rho" ) ;
2024-01-19 20:35:47 +00:00
expect ( sqlTiddlerStore . getRecipeTiddler ( "More" , "recipe-rho" ) . tiddler ) . toEqual ( { title : "More" , text : "None" } ) ;
2024-01-03 16:27:13 +00:00
2024-01-02 14:39:14 +00:00
} ) ;
} ) ;
}
} ) ( ) ;