Fix mock server to fix specs.
This commit is contained in:
parent
8fd20a0f35
commit
c2232a6d01
@ -1,7 +1,10 @@
|
|||||||
!function(){
|
var $ = require('jquery');
|
||||||
'use strict';
|
var Backbone = require('backbone');
|
||||||
|
var _ = require('underscore');
|
||||||
|
require('../backbone-model-file-upload');
|
||||||
|
var Blob = require('blob');
|
||||||
|
|
||||||
describe('Testing Backbone Model Plugin', function(){
|
describe('Testing Backbone Model Plugin', function () {
|
||||||
|
|
||||||
Backbone.$.ajaxSetup({
|
Backbone.$.ajaxSetup({
|
||||||
headers: {
|
headers: {
|
||||||
@ -19,7 +22,7 @@
|
|||||||
var fileModel;
|
var fileModel;
|
||||||
var simulatedFileObj;
|
var simulatedFileObj;
|
||||||
|
|
||||||
beforeEach(function(){
|
beforeEach(function () {
|
||||||
|
|
||||||
simulatedFileObj = new Blob(['<strong>Hello World</strong>'], {type : 'text/html'});
|
simulatedFileObj = new Blob(['<strong>Hello World</strong>'], {type : 'text/html'});
|
||||||
|
|
||||||
@ -41,7 +44,7 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should detect the file(blob) save successfully', function(done){
|
it('should detect the file(blob) save successfully', function (done) {
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
fileModel.set({fileAttachment: simulatedFileObj});
|
fileModel.set({fileAttachment: simulatedFileObj});
|
||||||
@ -66,7 +69,7 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('should be able to be saved in as an argument of "save" as object', function(done){
|
it ('should be able to be saved in as an argument of "save" as object', function (done) {
|
||||||
|
|
||||||
// Listen
|
// Listen
|
||||||
fileModel.on('sync', function(model){
|
fileModel.on('sync', function(model){
|
||||||
@ -88,7 +91,7 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('should be able to be saved in as an argument of "save" as key/value argument', function(done){
|
it ('should be able to be saved in as an argument of "save" as key/value argument', function (done) {
|
||||||
|
|
||||||
// Listen
|
// Listen
|
||||||
fileModel.on('sync', function(model){
|
fileModel.on('sync', function(model){
|
||||||
@ -109,7 +112,7 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('should be able to have "wait" and "validate" option', function(done){
|
it ('should be able to have "wait" and "validate" option', function (done) {
|
||||||
|
|
||||||
// Listen
|
// Listen
|
||||||
fileModel.on('sync', function(model){
|
fileModel.on('sync', function(model){
|
||||||
@ -130,7 +133,7 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should still have the option to save normally by setting it and save(null)', function(done){
|
it('should still have the option to save normally by setting it and save(null)', function (done) {
|
||||||
|
|
||||||
// Listen
|
// Listen
|
||||||
fileModel.on('sync', function(model){
|
fileModel.on('sync', function(model){
|
||||||
@ -149,7 +152,7 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should still have the option to save normally by save("from","yes")', function(done){
|
it('should still have the option to save normally by save("from","yes")', function (done) {
|
||||||
|
|
||||||
// Listen
|
// Listen
|
||||||
fileModel.on('sync', function(model){
|
fileModel.on('sync', function(model){
|
||||||
@ -167,7 +170,7 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should still have the option to save normally by save({from: "yes"})', function(done){
|
it('should still have the option to save normally by save({from: "yes"})', function (done) {
|
||||||
|
|
||||||
// Listen
|
// Listen
|
||||||
fileModel.on('sync', function(model){
|
fileModel.on('sync', function(model){
|
||||||
@ -185,7 +188,7 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should still silent true with file', function(done){
|
it('should still silent true with file', function (done) {
|
||||||
|
|
||||||
var changed = false;
|
var changed = false;
|
||||||
|
|
||||||
@ -214,7 +217,7 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should still silent true without file', function(done){
|
it('should still silent true without file', function (done) {
|
||||||
|
|
||||||
var changed = false;
|
var changed = false;
|
||||||
|
|
||||||
@ -240,7 +243,7 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should flatten correctly using a bracket notation', function(){
|
it('should flatten correctly using a bracket notation', function () {
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
var expected = {
|
var expected = {
|
||||||
@ -261,7 +264,7 @@
|
|||||||
expect(flattened["nestedObject[nestier[nestiest[2]]]"]).toBe("three");
|
expect(flattened["nestedObject[nestier[nestiest[2]]]"]).toBe("three");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should unflatten correctly using internal "unflatten" function', function(){
|
it('should unflatten correctly using internal "unflatten" function', function () {
|
||||||
|
|
||||||
var flattened = fileModel._flatten(fileModel.toJSON()),
|
var flattened = fileModel._flatten(fileModel.toJSON()),
|
||||||
unflattened = fileModel._unflatten(flattened);
|
unflattened = fileModel._unflatten(flattened);
|
||||||
@ -291,7 +294,5 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}();
|
|
@ -1,10 +1,8 @@
|
|||||||
'use strict';
|
var http = require('http');
|
||||||
|
var formidable = require('formidable');
|
||||||
var http = require('http'),
|
var fs = require('fs');
|
||||||
formidable = require('formidable'),
|
var _ = require('underscore');
|
||||||
fs = require('fs'),
|
var util = require('util');
|
||||||
_ = require('lodash');
|
|
||||||
|
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
@ -41,6 +39,7 @@ var server = http.createServer(function(req,res) {
|
|||||||
|
|
||||||
output[i] = {};
|
output[i] = {};
|
||||||
|
|
||||||
|
// This is fucking async
|
||||||
fs.readFile(files[i].path, function (err, data) {
|
fs.readFile(files[i].path, function (err, data) {
|
||||||
|
|
||||||
output[i].type = files[i].type;
|
output[i].type = files[i].type;
|
||||||
@ -49,16 +48,17 @@ var server = http.createServer(function(req,res) {
|
|||||||
output[i].lastModifiedDate = files[i].lastModifiedDate;
|
output[i].lastModifiedDate = files[i].lastModifiedDate;
|
||||||
output[i].data = 'data:' + files[i].type + ';base64,' + data.toString('base64');
|
output[i].data = 'data:' + files[i].type + ';base64,' + data.toString('base64');
|
||||||
|
|
||||||
|
console.info(output);
|
||||||
|
res.end(JSON.stringify(output));
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else {
|
||||||
|
|
||||||
console.info(output);
|
console.info(output);
|
||||||
|
|
||||||
res.end(JSON.stringify(output));
|
res.end(JSON.stringify(output));
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -83,4 +83,4 @@ function unflatten(obj, output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
server.listen(options.port, options.host);
|
server.listen(options.port, options.host);
|
||||||
console.log("listening on " + options.host + ':' + options.port);
|
console.info("listening on " + options.host + ':' + options.port);
|
||||||
|
Loading…
Reference in New Issue
Block a user