Last active
December 12, 2015 07:38
-
-
Save viezel/4737867 to your computer and use it in GitHub Desktop.
behave restsql test v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Setup module to run Behave tests | |
require('behave').andSetup(this); | |
describe('SQLREST: create a model', function() { | |
it.eventually('*** creates a new model', function(done) { | |
var model = Alloy.createModel('wine', { | |
name : "CHATEAU LE DOYENNE", | |
year : 2012, | |
grapes : "Merlot", | |
country : "France", | |
region : "Bordeaux", | |
description : "Though dense and chewy, this wine does not overpower with its finely balanced depth and structure." | |
}); | |
model.save({}, { | |
success : function(returnModel) { | |
// get model back from db | |
Ti.API.info("callback"); | |
model.set({ | |
"id" : returnModel.id | |
}); | |
model.fetch(); | |
// validate it | |
expect(model.id).notToBe(null); | |
expect(model.id).toBe(returnModel.id); | |
expect(model.get("name")).toBe('CHATEAU LE DOYENNE'); | |
expect(model.get("year")).toBe("2012"); | |
//?? It should be an int - but then it fails | |
//model.destroy(); | |
done(); | |
}, | |
error : function(returnModel) { | |
//on error - the data is only saved to local db | |
Ti.API.debug("create model: error callback"); | |
// get model back from db | |
model.set({ | |
"id" : returnModel.id | |
}); | |
model.fetch(); | |
// validate it | |
expect(model.id).notToBe(null); | |
expect(model.id).toBe(returnModel.id); | |
expect(model.get("name")).toBe('CHATEAU LE DOYENNE'); | |
expect(model.get("year")).toBe("2012"); | |
//model.destroy(); | |
done(); | |
} | |
}); | |
}, 10000); | |
}); | |
describe('SQLREST: create and update a model', function() { | |
it.eventually('*** creates a new model', function(done) { | |
var model = Alloy.createModel('wine', { | |
name : "CHATEAU LE DOYENNE", | |
year : 2012, | |
grapes : "Merlot", | |
country : "France", | |
region : "Bordeaux", | |
description : "Though dense and chewy, this wine does not overpower with its finely balanced depth and structure." | |
}); | |
model.save({}, { | |
success : function(returnModel) { | |
// get model back from db | |
Ti.API.info("callback"); | |
model.set({ | |
"id" : returnModel.id | |
}); | |
model.fetch(); | |
// validate it | |
expect(model.id).notToBe(null); | |
expect(model.id).toBe(returnModel.id); | |
expect(model.get("name")).toBe('CHATEAU LE DOYENNE'); | |
expect(model.get("year")).toBe("2012"); | |
//?? It should be an int - but then it fails | |
//UPDATE the model | |
it.eventually('*** updates the model', function(_done) { | |
var model = Alloy.createModel('wine', { | |
id : returnModel.id, //when ID is defined, backbone will update rather than create | |
name : "CHATEAU LE DOYENNE", | |
year : 2012, | |
grapes : "Merlot", | |
country : "Denmark", | |
region : "Copenhagen", | |
description : "Danish wines are horrible." | |
}); | |
/* | |
model.set({ | |
"region": "Copenhagen", | |
"country": "Denmark", | |
"description": "Danish wines are horrible." | |
}); | |
*/ | |
model.save({ | |
success : function(_returnModel) { | |
expect(model.id).notToBe(null); | |
expect(model.id).toBe(_returnModel.id); | |
expect(model.get("region")).toBe('Copenhagen'); | |
expect(model.get("country")).toBe("Denmark"); | |
expect(model.get("description")).toBe("Danish wines are horrible."); | |
_done(); | |
//model.destroy(); | |
}, | |
error : function(_returnModel) { | |
expect(model.id).notToBe(null); | |
expect(model.id).toBe(_returnModel.id); | |
expect(model.get("region")).toBe('Copenhagen'); | |
expect(model.get("country")).toBe("Denmark"); | |
expect(model.get("description")).toBe("Danish wines are horrible."); | |
_done(); | |
//model.destroy(); | |
} | |
}); | |
}, 10000); | |
done(); | |
}, | |
error : function(returnModel) { | |
//on error - the data is only saved to local db | |
Ti.API.debug("create model: error callback"); | |
// get model back from db | |
model.set({ | |
"id" : returnModel.id | |
}); | |
model.fetch(); | |
// validate it | |
expect(model.id).notToBe(null); | |
expect(model.id).toBe(returnModel.id); | |
expect(model.get("name")).toBe('CHATEAU LE DOYENNE'); | |
expect(model.get("year")).toBe("2012"); | |
done(); | |
model.destroy(); | |
} | |
}); | |
}, 10000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment