Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Vincent Bechu
jio
Commits
97dd3e10
Commit
97dd3e10
authored
Oct 28, 2016
by
Vincent Bechu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mappingstorage: fix post, add test, and change function names
parent
f0552bec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
253 additions
and
176 deletions
+253
-176
src/jio.storage/mappingstorage.js
src/jio.storage/mappingstorage.js
+62
-54
test/jio.storage/mappingstorage.tests.js
test/jio.storage/mappingstorage.tests.js
+191
-122
No files found.
src/jio.storage/mappingstorage.js
View file @
97dd3e10
...
@@ -7,21 +7,25 @@
...
@@ -7,21 +7,25 @@
function
MappingStorage
(
spec
)
{
function
MappingStorage
(
spec
)
{
this
.
_mapping_dict
=
spec
.
mapping_dict
||
{};
this
.
_mapping_dict
=
spec
.
mapping_dict
||
{};
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_map_all_property
=
spec
.
map_all_property
||
false
;
this
.
_map_all_property
=
spec
.
map_all_property
!==
undefined
?
this
.
_mapping_dict_attachment
=
spec
.
mapping_dict_attachment
||
{};
spec
.
map_all_property
:
true
;
this
.
_attachment_mapping_dict
=
spec
.
attachment_mapping_dict
||
{};
this
.
_query
=
spec
.
query
||
{};
this
.
_query
=
spec
.
query
||
{};
if
(
this
.
_query
.
query
!==
undefined
)
{
if
(
this
.
_query
.
query
!==
undefined
)
{
this
.
_query
.
query
=
QueryFactory
.
create
(
this
.
_query
.
query
);
this
.
_query
.
query
=
QueryFactory
.
create
(
this
.
_query
.
query
);
}
}
this
.
_default_mapping
=
{};
this
.
_id_is_mapped
=
(
this
.
_mapping_dict
.
id
!==
undefined
this
.
_id_is_mapped
=
(
this
.
_mapping_dict
.
id
!==
undefined
&&
this
.
_mapping_dict
.
id
.
equal
!==
"
id
"
);
&&
this
.
_mapping_dict
.
id
.
equal
!==
"
id
"
);
var
property
,
query_list
=
[];
var
property
,
query_list
=
[];
// handle default_value.
// handle default_value.
for
(
property
in
this
.
_mapping_dict
)
{
for
(
property
in
this
.
_mapping_dict
)
{
if
(
this
.
_mapping_dict
.
hasOwnProperty
(
property
))
{
if
(
this
.
_mapping_dict
.
hasOwnProperty
(
property
))
{
if
(
this
.
_mapping_dict
[
property
].
default_value
!==
undefined
)
{
if
(
this
.
_mapping_dict
[
property
].
default_value
!==
undefined
)
{
this
.
_default_mapping
[
property
]
=
this
.
_mapping_dict
[
property
].
default_value
;
query_list
.
push
(
new
SimpleQuery
({
query_list
.
push
(
new
SimpleQuery
({
key
:
property
,
key
:
property
,
value
:
this
.
_mapping_dict
[
property
].
default_value
,
value
:
this
.
_mapping_dict
[
property
].
default_value
,
...
@@ -47,7 +51,7 @@
...
@@ -47,7 +51,7 @@
}
}
function
getAttachmentId
(
storage
,
sub_id
,
attachment_id
,
method
)
{
function
getAttachmentId
(
storage
,
sub_id
,
attachment_id
,
method
)
{
var
mapping_dict
=
storage
.
_
mapping_dict_attachmen
t
;
var
mapping_dict
=
storage
.
_
attachment_mapping_dic
t
;
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
if
(
mapping_dict
!==
undefined
if
(
mapping_dict
!==
undefined
...
@@ -106,13 +110,19 @@
...
@@ -106,13 +110,19 @@
});
});
}
}
function
unmapProperty
(
storage
,
property
,
doc
,
mapped_doc
)
{
function
mapToSubProperty
(
storage
,
property
,
sub_doc
,
doc
)
{
if
(
storage
.
_mapping_dict
[
property
].
equal
!==
undefined
)
{
if
(
storage
.
_mapping_dict
[
property
]
!==
undefined
)
{
doc
[
storage
.
_mapping_dict
[
property
].
equal
]
=
mapped_doc
[
property
];
if
(
storage
.
_mapping_dict
[
property
].
equal
!==
undefined
)
{
return
storage
.
_mapping_dict
[
property
].
equal
;
sub_doc
[
storage
.
_mapping_dict
[
property
].
equal
]
=
doc
[
property
];
return
storage
.
_mapping_dict
[
property
].
equal
;
}
if
(
storage
.
_mapping_dict
[
property
].
default_value
!==
undefined
)
{
sub_doc
[
property
]
=
storage
.
_mapping_dict
[
property
].
default_value
;
return
property
;
}
}
}
if
(
storage
.
_map
ping_dict
[
property
].
default_value
!==
undefined
)
{
if
(
storage
.
_map
_all_property
)
{
doc
[
property
]
=
storage
.
_mapping_dict
[
property
].
default_value
;
sub_doc
[
property
]
=
doc
[
property
]
;
return
property
;
return
property
;
}
}
throw
new
jIO
.
util
.
jIOError
(
throw
new
jIO
.
util
.
jIOError
(
...
@@ -121,11 +131,11 @@
...
@@ -121,11 +131,11 @@
);
);
}
}
function
map
Property
(
storage
,
property
,
doc
,
mapped_
doc
)
{
function
map
ToMainProperty
(
storage
,
property
,
sub_doc
,
doc
)
{
if
(
storage
.
_mapping_dict
[
property
]
!==
undefined
)
{
if
(
storage
.
_mapping_dict
[
property
]
!==
undefined
)
{
if
(
storage
.
_mapping_dict
[
property
].
equal
!==
undefined
)
{
if
(
storage
.
_mapping_dict
[
property
].
equal
!==
undefined
)
{
if
(
doc
.
hasOwnProperty
(
storage
.
_mapping_dict
[
property
].
equal
))
{
if
(
sub_
doc
.
hasOwnProperty
(
storage
.
_mapping_dict
[
property
].
equal
))
{
mapped_doc
[
property
]
=
doc
[
storage
.
_mapping_dict
[
property
].
equal
];
doc
[
property
]
=
sub_
doc
[
storage
.
_mapping_dict
[
property
].
equal
];
}
}
return
storage
.
_mapping_dict
[
property
].
equal
;
return
storage
.
_mapping_dict
[
property
].
equal
;
}
}
...
@@ -134,56 +144,53 @@
...
@@ -134,56 +144,53 @@
}
}
}
}
if
(
storage
.
_map_all_property
)
{
if
(
storage
.
_map_all_property
)
{
if
(
doc
.
hasOwnProperty
(
property
))
{
if
(
sub_
doc
.
hasOwnProperty
(
property
))
{
mapped_doc
[
property
]
=
doc
[
property
];
doc
[
property
]
=
sub_
doc
[
property
];
}
}
return
property
;
return
property
;
}
}
return
false
;
return
false
;
}
}
function
map
Document
(
storage
,
doc
,
id_delete
)
{
function
map
ToMainDocument
(
storage
,
sub_doc
,
delete_id_from_doc
)
{
var
mapped_
doc
=
{},
var
doc
=
{},
property
,
property
,
property_list
=
[];
property_list
=
[];
for
(
property
in
storage
.
_mapping_dict
)
{
for
(
property
in
storage
.
_mapping_dict
)
{
if
(
storage
.
_mapping_dict
.
hasOwnProperty
(
property
))
{
if
(
storage
.
_mapping_dict
.
hasOwnProperty
(
property
))
{
property_list
.
push
(
map
Property
(
storage
,
property
,
doc
,
mapped_
doc
));
property_list
.
push
(
map
ToMainProperty
(
storage
,
property
,
sub_doc
,
doc
));
}
}
}
}
if
(
storage
.
_map_all_property
)
{
if
(
storage
.
_map_all_property
)
{
for
(
property
in
doc
)
{
for
(
property
in
sub_
doc
)
{
if
(
doc
.
hasOwnProperty
(
property
))
{
if
(
sub_
doc
.
hasOwnProperty
(
property
))
{
if
(
property_list
.
indexOf
(
property
)
<
0
)
{
if
(
property_list
.
indexOf
(
property
)
<
0
)
{
mapped_doc
[
property
]
=
doc
[
property
];
doc
[
property
]
=
sub_
doc
[
property
];
}
}
}
}
}
}
}
}
if
(
id_delete
)
{
if
(
delete_id_from_doc
)
{
delete
mapped_
doc
.
id
;
delete
doc
.
id
;
}
}
return
mapped_
doc
;
return
doc
;
}
}
function
unmapDocument
(
storage
,
mapped_doc
)
{
function
mapToSubstorageDocument
(
storage
,
doc
)
{
var
doc
=
{},
property
,
property_list
=
[];
var
sub_doc
=
{},
property
;
for
(
property
in
storage
.
_mapping_dict
)
{
if
(
storage
.
_mapping_dict
.
hasOwnProperty
(
property
))
{
for
(
property
in
doc
)
{
property_list
.
push
(
unmapProperty
(
storage
,
property
,
doc
,
mapped_doc
));
if
(
doc
.
hasOwnProperty
(
property
))
{
mapToSubProperty
(
storage
,
property
,
sub_doc
,
doc
);
}
}
}
}
if
(
storage
.
_map_all_property
)
{
for
(
property
in
storage
.
_default_mapping
)
{
for
(
property
in
mapped_doc
)
{
if
(
storage
.
_default_mapping
.
hasOwnProperty
(
property
))
{
if
(
mapped_doc
.
hasOwnProperty
(
property
))
{
sub_doc
[
property
]
=
storage
.
_default_mapping
[
property
];
if
(
property_list
.
indexOf
(
property
)
<
0
)
{
doc
[
property
]
=
mapped_doc
[
property
];
}
}
}
}
}
}
delete
doc
.
id
;
delete
sub_
doc
.
id
;
return
doc
;
return
sub_
doc
;
}
}
MappingStorage
.
prototype
.
get
=
function
(
id
)
{
MappingStorage
.
prototype
.
get
=
function
(
id
)
{
...
@@ -192,8 +199,8 @@
...
@@ -192,8 +199,8 @@
.
push
(
function
(
sub_id
)
{
.
push
(
function
(
sub_id
)
{
return
context
.
_sub_storage
.
get
(
sub_id
);
return
context
.
_sub_storage
.
get
(
sub_id
);
})
})
.
push
(
function
(
doc
)
{
.
push
(
function
(
sub_
doc
)
{
return
map
Document
(
context
,
doc
,
true
);
return
map
ToMainDocument
(
context
,
sub_
doc
,
true
);
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
+
id
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
+
id
...
@@ -201,30 +208,31 @@
...
@@ -201,30 +208,31 @@
});
});
};
};
MappingStorage
.
prototype
.
post
=
function
(
doc
_mapped
)
{
MappingStorage
.
prototype
.
post
=
function
(
doc
)
{
if
(
!
this
.
_id_is_mapped
)
{
if
(
!
this
.
_id_is_mapped
)
{
return
this
.
_sub_storage
.
post
.
apply
(
return
this
.
_sub_storage
.
post
(
mapToSubstorageDocument
(
this
,
doc
));
this
.
_sub_storage
,
unmapDocument
(
this
,
doc_mapped
)
);
}
}
throw
new
jIO
.
util
.
jIOError
(
"
post is not supported with id mapped
"
,
400
);
};
};
MappingStorage
.
prototype
.
put
=
function
(
id
,
doc
)
{
MappingStorage
.
prototype
.
put
=
function
(
id
,
doc
)
{
var
context
=
this
,
var
context
=
this
,
mapped_doc
=
unmap
Document
(
this
,
doc
);
sub_doc
=
mapToSubstorage
Document
(
this
,
doc
);
return
getSubStorageId
(
this
,
id
)
return
getSubStorageId
(
this
,
id
)
.
push
(
function
(
sub_id
)
{
.
push
(
function
(
sub_id
)
{
if
(
context
.
_id_is_mapped
)
{
if
(
context
.
_id_is_mapped
)
{
mapped
_doc
[
context
.
_mapping_dict
.
id
.
equal
]
=
id
;
sub
_doc
[
context
.
_mapping_dict
.
id
.
equal
]
=
id
;
}
}
if
(
id
===
undefined
)
{
if
(
id
===
undefined
)
{
throw
new
Error
();
throw
new
Error
();
}
}
return
context
.
_sub_storage
.
put
(
sub_id
,
mapped
_doc
);
return
context
.
_sub_storage
.
put
(
sub_id
,
sub
_doc
);
})
})
.
push
(
undefined
,
function
()
{
.
push
(
undefined
,
function
()
{
return
context
.
_sub_storage
.
post
(
mapped
_doc
);
return
context
.
_sub_storage
.
post
(
sub
_doc
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
id
;
return
id
;
...
@@ -318,7 +326,7 @@
...
@@ -318,7 +326,7 @@
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
for
(
i
=
0
;
i
<
result
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
result
.
length
;
i
+=
1
)
{
mapped_result
.
push
(
mapDocument
(
context
,
result
[
i
],
false
));
mapped_result
.
push
(
map
ToMain
Document
(
context
,
result
[
i
],
false
));
}
}
return
mapped_result
;
return
mapped_result
;
});
});
...
@@ -341,13 +349,13 @@
...
@@ -341,13 +349,13 @@
one_query
.
query_list
=
query_list
;
one_query
.
query_list
=
query_list
;
return
one_query
;
return
one_query
;
}
}
one_query
.
key
=
mapProperty
(
context
,
one_query
.
key
,
{},
{});
one_query
.
key
=
map
ToMain
Property
(
context
,
one_query
.
key
,
{},
{});
return
one_query
;
return
one_query
;
}
}
if
(
option
.
sort_on
!==
undefined
)
{
if
(
option
.
sort_on
!==
undefined
)
{
for
(
i
=
0
;
i
<
option
.
sort_on
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
option
.
sort_on
.
length
;
i
+=
1
)
{
property
=
mapProperty
(
this
,
option
.
sort_on
[
i
][
0
],
{},
{});
property
=
map
ToMain
Property
(
this
,
option
.
sort_on
[
i
][
0
],
{},
{});
if
(
property
&&
sort_on
.
indexOf
(
property
)
<
0
)
{
if
(
property
&&
sort_on
.
indexOf
(
property
)
<
0
)
{
select_list
.
push
([
property
,
option
.
sort_on
[
i
][
1
]]);
select_list
.
push
([
property
,
option
.
sort_on
[
i
][
1
]]);
}
}
...
@@ -363,7 +371,7 @@
...
@@ -363,7 +371,7 @@
}
}
if
(
option
.
select_list
!==
undefined
)
{
if
(
option
.
select_list
!==
undefined
)
{
for
(
i
=
0
;
i
<
option
.
select_list
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
option
.
select_list
.
length
;
i
+=
1
)
{
property
=
mapProperty
(
this
,
option
.
select_list
[
i
],
{},
{});
property
=
map
ToMain
Property
(
this
,
option
.
select_list
[
i
],
{},
{});
if
(
property
&&
select_list
.
indexOf
(
property
)
<
0
)
{
if
(
property
&&
select_list
.
indexOf
(
property
)
<
0
)
{
select_list
.
push
(
property
);
select_list
.
push
(
property
);
}
}
...
@@ -409,7 +417,7 @@
...
@@ -409,7 +417,7 @@
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
for
(
i
=
0
;
i
<
result
.
data
.
total_rows
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
result
.
data
.
total_rows
;
i
+=
1
)
{
result
.
data
.
rows
[
i
].
value
=
result
.
data
.
rows
[
i
].
value
=
mapDocument
(
context
,
result
.
data
.
rows
[
i
].
value
,
false
);
map
ToMain
Document
(
context
,
result
.
data
.
rows
[
i
].
value
,
false
);
if
(
result
.
data
.
rows
[
i
].
id
!==
undefined
&&
context
.
_id_is_mapped
)
{
if
(
result
.
data
.
rows
[
i
].
id
!==
undefined
&&
context
.
_id_is_mapped
)
{
result
.
data
.
rows
[
i
].
id
=
result
.
data
.
rows
[
i
].
id
=
result
.
data
.
rows
[
i
].
value
.
id
;
result
.
data
.
rows
[
i
].
value
.
id
;
...
...
test/jio.storage/mappingstorage.tests.js
View file @
97dd3e10
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
deepEqual
(
jio
.
__storage
.
_mapping_dict
,
{});
deepEqual
(
jio
.
__storage
.
_mapping_dict
,
{});
deepEqual
(
jio
.
__storage
.
_mapping_dict_attachment
,
{});
deepEqual
(
jio
.
__storage
.
_mapping_dict_attachment
,
{});
deepEqual
(
jio
.
__storage
.
_query
,
{});
deepEqual
(
jio
.
__storage
.
_query
,
{});
equal
(
jio
.
__storage
.
_map_all_property
,
fals
e
);
equal
(
jio
.
__storage
.
_map_all_property
,
tru
e
);
});
});
test
(
"
accept parameters
"
,
function
()
{
test
(
"
accept parameters
"
,
function
()
{
...
@@ -47,7 +47,7 @@
...
@@ -47,7 +47,7 @@
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
},
},
mapping_dict
:
{
"
bar
"
:
{
"
equal
"
:
"
foo
"
}},
mapping_dict
:
{
"
bar
"
:
{
"
equal
"
:
"
foo
"
}},
map_all_property
:
tru
e
,
map_all_property
:
fals
e
,
query
:
{
"
query
"
:
'
foo: "bar"
'
},
query
:
{
"
query
"
:
'
foo: "bar"
'
},
mapping_dict_attachment
:
{
"
foo
"
:
{
"
get
"
:
"
bar
"
}}
mapping_dict_attachment
:
{
"
foo
"
:
{
"
get
"
:
"
bar
"
}}
});
});
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
equal
(
jio
.
__storage
.
_query
.
query
.
value
,
"
bar
"
);
equal
(
jio
.
__storage
.
_query
.
query
.
value
,
"
bar
"
);
equal
(
jio
.
__storage
.
_query
.
query
.
type
,
"
simple
"
);
equal
(
jio
.
__storage
.
_query
.
query
.
type
,
"
simple
"
);
deepEqual
(
jio
.
__storage
.
_mapping_dict_attachment
,
{
"
foo
"
:
{
"
get
"
:
"
bar
"
}});
deepEqual
(
jio
.
__storage
.
_mapping_dict_attachment
,
{
"
foo
"
:
{
"
get
"
:
"
bar
"
}});
equal
(
jio
.
__storage
.
_map_all_property
,
tru
e
);
equal
(
jio
.
__storage
.
_map_all_property
,
fals
e
);
});
});
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
@@ -82,17 +82,15 @@
...
@@ -82,17 +82,15 @@
return
{
title
:
"
foo
"
};
return
{
title
:
"
foo
"
};
};
};
start
();
jio
.
get
(
"
bar
"
)
jio
.
get
(
"
bar
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
"
title
"
:
"
foo
"
},
"
Check document
"
);
},
"
Check document
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -113,16 +111,14 @@
...
@@ -113,16 +111,14 @@
return
{
otherTitle
:
"
foo
"
};
return
{
otherTitle
:
"
foo
"
};
};
};
start
();
jio
.
get
(
"
bar
"
)
jio
.
get
(
"
bar
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
"
title
"
:
"
foo
"
});
});
}).
fail
(
function
(
error
)
{
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -155,16 +151,14 @@
...
@@ -155,16 +151,14 @@
return
{
"
otherTitle
"
:
"
foo
"
};
return
{
"
otherTitle
"
:
"
foo
"
};
};
};
start
();
jio
.
get
(
"
42
"
)
jio
.
get
(
"
42
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
"
title
"
:
"
foo
"
});
});
}).
fail
(
function
(
error
)
{
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -202,16 +196,14 @@
...
@@ -202,16 +196,14 @@
return
{
"
otherTitle
"
:
"
foo
"
};
return
{
"
otherTitle
"
:
"
foo
"
};
};
};
start
();
jio
.
get
(
"
42
"
)
jio
.
get
(
"
42
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
"
title
"
:
"
foo
"
});
});
}).
fail
(
function
(
error
)
{
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -226,8 +218,7 @@
...
@@ -226,8 +218,7 @@
},
},
mapping_dict
:
{
mapping_dict
:
{
"
id
"
:
{
"
equal
"
:
"
otherId
"
}
"
id
"
:
{
"
equal
"
:
"
otherId
"
}
},
}
map_all_property
:
true
});
});
Storage2713
.
prototype
.
hasCapacity
=
function
()
{
Storage2713
.
prototype
.
hasCapacity
=
function
()
{
...
@@ -248,16 +239,14 @@
...
@@ -248,16 +239,14 @@
return
{
"
title
"
:
"
foo
"
};
return
{
"
title
"
:
"
foo
"
};
};
};
start
();
jio
.
get
(
"
42
"
)
jio
.
get
(
"
42
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
"
title
"
:
"
foo
"
});
});
}).
fail
(
function
(
error
)
{
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -284,15 +273,13 @@
...
@@ -284,15 +273,13 @@
return
id
;
return
id
;
};
};
start
();
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo
"
})
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
equal
(
result
,
"
bar
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -313,15 +300,13 @@
...
@@ -313,15 +300,13 @@
return
id
;
return
id
;
};
};
start
();
jio
.
put
(
"
bar
"
,
{})
jio
.
put
(
"
bar
"
,
{})
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
equal
(
result
,
"
bar
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -354,15 +339,13 @@
...
@@ -354,15 +339,13 @@
return
[];
return
[];
};
};
start
();
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
})
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
42
"
);
equal
(
result
,
"
42
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -387,17 +370,16 @@
...
@@ -387,17 +370,16 @@
return
id
;
return
id
;
};
};
start
();
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
,
"
smth
"
:
"
bar
"
,
"
smth2
"
:
"
bar2
"
})
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
,
"
smth
"
:
"
bar
"
,
"
smth2
"
:
"
bar2
"
})
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
42
"
);
equal
(
result
,
"
42
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// mappingStorage.remove
// mappingStorage.remove
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
@@ -417,15 +399,13 @@
...
@@ -417,15 +399,13 @@
return
id
;
return
id
;
};
};
start
();
jio
.
remove
(
"
bar
"
,
{
"
title
"
:
"
foo
"
})
jio
.
remove
(
"
bar
"
,
{
"
title
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
equal
(
result
,
"
bar
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -457,17 +437,67 @@
...
@@ -457,17 +437,67 @@
return
"
foo
"
;
return
"
foo
"
;
};
};
start
();
jio
.
remove
(
"
42
"
)
jio
.
remove
(
"
42
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
42
"
);
equal
(
result
,
"
42
"
);
}).
fail
(
function
(
error
)
{
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
});
});
/////////////////////////////////////////////////////////////////
// mappingStorage.remove
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.post
"
);
test
(
"
post with mapped property
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
sub_storage
:
{
type
:
"
mappingstorage2713
"
},
mapping_dict
:
{
"
title
"
:
{
"
equal
"
:
"
otherTitle
"
}}
});
Storage2713
.
prototype
.
post
=
function
(
doc
)
{
deepEqual
(
doc
,
{
"
otherTitle
"
:
"
foo
"
},
"
remove 2713 called
"
);
return
"
42
"
;
};
start
();
jio
.
post
({
"
title
"
:
"
foo
"
})
.
push
(
function
(
result
)
{
equal
(
result
,
"
42
"
);
})
})
.
always
(
function
(
)
{
.
push
(
undefined
,
function
(
error
)
{
start
(
);
ok
(
false
,
error
);
});
});
});
});
test
(
"
post with id mapped
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
sub_storage
:
{
type
:
"
mappingstorage2713
"
},
mapping_dict
:
{
"
id
"
:
{
"
equal
"
:
"
otherId
"
}}
});
Storage2713
.
prototype
.
post
=
function
()
{
return
false
;
};
start
();
jio
.
post
({
"
title
"
:
"
foo
"
})
.
push
(
undefined
,
function
(
error
)
{
equal
(
error
.
message
,
"
post is not supported with id mapped
"
);
equal
(
error
.
status_code
,
400
);
});
});
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// mappingStorage.putAttachment
// mappingStorage.putAttachment
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
@@ -490,15 +520,14 @@
...
@@ -490,15 +520,14 @@
deepEqual
(
attachment
,
blob
,
"
putAttachment 2713 called
"
);
deepEqual
(
attachment
,
blob
,
"
putAttachment 2713 called
"
);
return
doc_id
;
return
doc_id
;
};
};
start
();
jio
.
putAttachment
(
"
42
"
,
"
2713
"
,
blob
)
jio
.
putAttachment
(
"
42
"
,
"
2713
"
,
blob
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
2713
"
);
equal
(
result
,
"
2713
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -521,15 +550,14 @@
...
@@ -521,15 +550,14 @@
deepEqual
(
attachment
,
blob
,
"
putAttachment 2713 called
"
);
deepEqual
(
attachment
,
blob
,
"
putAttachment 2713 called
"
);
return
doc_id
;
return
doc_id
;
};
};
start
();
jio
.
putAttachment
(
"
42
"
,
"
2713
"
,
blob
)
jio
.
putAttachment
(
"
42
"
,
"
2713
"
,
blob
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
2713
"
);
equal
(
result
,
"
2713
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -564,15 +592,13 @@
...
@@ -564,15 +592,13 @@
return
[{
"
id
"
:
"
13
"
}];
return
[{
"
id
"
:
"
13
"
}];
};
};
start
();
jio
.
putAttachment
(
"
42
"
,
"
2713
"
,
blob
)
jio
.
putAttachment
(
"
42
"
,
"
2713
"
,
blob
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
2713
"
);
equal
(
result
,
"
2713
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -596,15 +622,14 @@
...
@@ -596,15 +622,14 @@
equal
(
attachment
,
"
2713
"
,
"
getAttachment 2713 called
"
);
equal
(
attachment
,
"
2713
"
,
"
getAttachment 2713 called
"
);
return
blob
;
return
blob
;
};
};
start
();
jio
.
getAttachment
(
"
42
"
,
"
2713
"
)
jio
.
getAttachment
(
"
42
"
,
"
2713
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
blob
);
deepEqual
(
result
,
blob
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -626,15 +651,14 @@
...
@@ -626,15 +651,14 @@
equal
(
doc_id
,
"
42
"
,
"
getAttachment 2713 called
"
);
equal
(
doc_id
,
"
42
"
,
"
getAttachment 2713 called
"
);
return
blob
;
return
blob
;
};
};
start
();
jio
.
getAttachment
(
"
42
"
,
"
2713
"
)
jio
.
getAttachment
(
"
42
"
,
"
2713
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
blob
);
deepEqual
(
result
,
blob
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -668,15 +692,13 @@
...
@@ -668,15 +692,13 @@
return
[{
"
id
"
:
"
13
"
}];
return
[{
"
id
"
:
"
13
"
}];
};
};
start
();
jio
.
getAttachment
(
"
42
"
,
"
2713
"
)
jio
.
getAttachment
(
"
42
"
,
"
2713
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
blob
);
deepEqual
(
result
,
blob
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -688,32 +710,34 @@
...
@@ -688,32 +710,34 @@
test
(
"
removeAttachment use sub_storage one's
"
,
function
()
{
test
(
"
removeAttachment use sub_storage one's
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
});
});
Storage2713
.
prototype
.
removeAttachment
=
function
(
doc_id
,
attachment
)
{
Storage2713
.
prototype
.
removeAttachment
=
function
(
doc_id
,
attachment
)
{
equal
(
doc_id
,
"
42
"
,
"
removeAttachment 2713 called
"
);
equal
(
doc_id
,
"
42
"
,
"
removeAttachment 2713 called
"
);
equal
(
attachment
,
"
2713
"
,
"
getAttachment 2713 called
"
);
equal
(
attachment
,
"
2713
"
,
"
getAttachment 2713 called
"
);
return
doc_id
;
return
doc_id
;
};
};
start
();
jio
.
removeAttachment
(
"
42
"
,
"
2713
"
)
jio
.
removeAttachment
(
"
42
"
,
"
2713
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
"
2713
"
);
deepEqual
(
result
,
"
2713
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
test
(
"
removeAttachment use UriTemplate
"
,
function
()
{
test
(
"
removeAttachment use UriTemplate
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
sub_storage
:
{
sub_storage
:
{
...
@@ -722,26 +746,27 @@
...
@@ -722,26 +746,27 @@
mapping_dict_attachment
:
{
"
2713
"
:
mapping_dict_attachment
:
{
"
2713
"
:
{
"
remove
"
:
{
"
uri_template
"
:
"
www.2713/{id}.bar
"
}}}
{
"
remove
"
:
{
"
uri_template
"
:
"
www.2713/{id}.bar
"
}}}
});
});
Storage2713
.
prototype
.
removeAttachment
=
function
(
doc_id
,
attachment
)
{
Storage2713
.
prototype
.
removeAttachment
=
function
(
doc_id
,
attachment
)
{
equal
(
doc_id
,
"
42
"
,
"
removeAttachment 2713 called
"
);
equal
(
doc_id
,
"
42
"
,
"
removeAttachment 2713 called
"
);
equal
(
attachment
,
"
www.2713/42.bar
"
,
"
removeAttachment 2713 called
"
);
equal
(
attachment
,
"
www.2713/42.bar
"
,
"
removeAttachment 2713 called
"
);
return
doc_id
;
return
doc_id
;
};
};
start
();
jio
.
removeAttachment
(
"
42
"
,
"
2713
"
)
jio
.
removeAttachment
(
"
42
"
,
"
2713
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
"
2713
"
);
deepEqual
(
result
,
"
2713
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
test
(
"
removeAttachment with UriTemplate and id mapped
"
,
function
()
{
test
(
"
removeAttachment with UriTemplate and id mapped
"
,
function
()
{
stop
();
stop
();
expect
(
4
);
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
sub_storage
:
{
sub_storage
:
{
...
@@ -768,15 +793,13 @@
...
@@ -768,15 +793,13 @@
return
[{
"
id
"
:
"
13
"
}];
return
[{
"
id
"
:
"
13
"
}];
};
};
start
();
jio
.
removeAttachment
(
"
42
"
,
"
2713
"
)
jio
.
removeAttachment
(
"
42
"
,
"
2713
"
)
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
2713
"
);
equal
(
result
,
"
2713
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -802,6 +825,7 @@
...
@@ -802,6 +825,7 @@
map_all_property
:
true
map_all_property
:
true
});
});
start
();
jio
.
put
(
"
42
"
,
jio
.
put
(
"
42
"
,
{
{
"
title
"
:
"
foo
"
,
"
title
"
:
"
foo
"
,
...
@@ -834,9 +858,6 @@
...
@@ -834,9 +858,6 @@
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -862,6 +883,7 @@
...
@@ -862,6 +883,7 @@
}
}
});
});
start
();
jio
.
put
(
"
42
"
,
jio
.
put
(
"
42
"
,
{
{
"
title
"
:
"
foo
"
,
"
title
"
:
"
foo
"
,
...
@@ -894,9 +916,6 @@
...
@@ -894,9 +916,6 @@
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -921,6 +940,7 @@
...
@@ -921,6 +940,7 @@
}
}
});
});
start
();
jio
.
put
(
"
42
"
,
jio
.
put
(
"
42
"
,
{
{
"
title
"
:
"
foo
"
,
"
title
"
:
"
foo
"
,
...
@@ -946,9 +966,6 @@
...
@@ -946,9 +966,6 @@
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
...
@@ -974,6 +991,7 @@
...
@@ -974,6 +991,7 @@
map_all_property
:
true
map_all_property
:
true
});
});
start
();
jio
.
put
(
"
42
"
,
jio
.
put
(
"
42
"
,
{
{
"
title
"
:
"
foo
"
,
"
title
"
:
"
foo
"
,
...
@@ -1002,9 +1020,60 @@
...
@@ -1002,9 +1020,60 @@
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
});
});
test
(
"
allDocs id and prop mapped and query
"
,
function
()
{
stop
();
expect
(
1
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
query
:
{
"
query
"
:
'
otherId: "42"
'
},
mapping_dict
:
{
"
id
"
:
{
"
equal
"
:
"
otherId
"
},
"
title
"
:
{
"
equal
"
:
"
otherTitle
"
}
},
sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
}
});
start
();
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
,
"
smth
"
:
"
bar
"
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
'
title: "foo"
'
,
select_list
:
[
"
title
"
]
});
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
data
"
:
{
"
rows
"
:
[
{
"
id
"
:
"
42
"
,
"
value
"
:
{
"
title
"
:
"
foo
"
},
"
doc
"
:
{}
}
],
"
total_rows
"
:
1
}
},
"
allDocs check
"
);
})
})
.
always
(
function
(
)
{
.
push
(
undefined
,
function
(
error
)
{
start
(
);
ok
(
false
,
error
);
});
});
});
});
...
@@ -1067,6 +1136,7 @@
...
@@ -1067,6 +1136,7 @@
];
];
};
};
start
();
jio
.
bulk
([{
jio
.
bulk
([{
method
:
"
get
"
,
method
:
"
get
"
,
parameter_list
:
[
"
id1
"
]
parameter_list
:
[
"
id1
"
]
...
@@ -1089,8 +1159,8 @@
...
@@ -1089,8 +1159,8 @@
"
bulk test
"
"
bulk test
"
);
);
})
})
.
always
(
function
(
)
{
.
push
(
undefined
,
function
(
error
)
{
start
(
);
ok
(
false
,
error
);
});
});
});
});
...
@@ -1116,15 +1186,14 @@
...
@@ -1116,15 +1186,14 @@
return
"
foobar
"
;
return
"
foobar
"
;
};
};
start
();
jio
.
repair
([
"
foo
"
,
"
bar
"
])
jio
.
repair
([
"
foo
"
,
"
bar
"
])
.
then
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
foobar
"
,
"
Check repair
"
);
equal
(
result
,
"
foobar
"
,
"
Check repair
"
);
})
})
.
fail
(
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
});
});
}(
jIO
,
QUnit
,
Blob
));
}(
jIO
,
QUnit
,
Blob
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment