Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Aurélien Vermylen
jio
Commits
74abb3a6
Commit
74abb3a6
authored
Jan 25, 2017
by
Vincent Bechu
Committed by
Aurel
Feb 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mappingstorage: add switchPropertyValue mapping function and tests
parent
316621f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
4 deletions
+90
-4
src/jio.storage/mappingstorage.js
src/jio.storage/mappingstorage.js
+17
-0
test/jio.storage/mappingstorage.tests.js
test/jio.storage/mappingstorage.tests.js
+73
-4
No files found.
src/jio.storage/mappingstorage.js
View file @
74abb3a6
...
...
@@ -119,6 +119,23 @@
doc
[
property
]
=
sub_doc
[
property
];
return
property
;
}
},
"
switchPropertyValue
"
:
{
"
mapToSubProperty
"
:
function
(
property
,
sub_doc
,
doc
,
args
)
{
sub_doc
[
args
[
0
]]
=
args
[
1
][
doc
[
property
]];
return
args
[
0
];
},
"
mapToMainProperty
"
:
function
(
property
,
sub_doc
,
doc
,
args
)
{
var
subvalue
,
value
=
sub_doc
[
args
[
0
]];
for
(
subvalue
in
args
[
1
])
{
if
(
args
[
1
].
hasOwnProperty
(
subvalue
))
{
if
(
value
===
args
[
1
][
subvalue
])
{
doc
[
property
]
=
subvalue
;
return
property
;
}
}
}
}
}
};
/*jslint unparam: false*/
...
...
test/jio.storage/mappingstorage.tests.js
View file @
74abb3a6
...
...
@@ -280,6 +280,42 @@
});
});
test
(
"
with switchPropertyValue
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
property
:
{
"
title
"
:
[
"
switchPropertyValue
"
,
[
"
subTitle
"
,
{
"
mytitle
"
:
"
title
"
,
"
yourtitle
"
:
"
othertitle
"
}
]],
"
subTitle
"
:
[
"
ignore
"
]
},
sub_storage
:
{
type
:
"
mappingstorage2713
"
}
});
Storage2713
.
prototype
.
get
=
function
(
id
)
{
equal
(
id
,
"
bar
"
,
"
get 2713 called
"
);
return
{
"
subTitle
"
:
"
title
"
};
};
jio
.
get
(
"
bar
"
)
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
mytitle
"
});
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// mappingStorage.put
/////////////////////////////////////////////////////////////////
...
...
@@ -373,7 +409,7 @@
Storage2713
.
prototype
.
put
=
function
(
id
,
doc
)
{
deepEqual
(
doc
,
{
"
otherId
"
:
"
42
"
},
"
post 2713 called
"
);
{
"
otherId
"
:
"
42
"
,
"
title
"
:
"
bar
"
},
"
post 2713 called
"
);
equal
(
id
,
"
bar
"
);
return
"
bar
"
;
};
...
...
@@ -404,7 +440,7 @@
Storage2713
.
prototype
.
put
=
function
(
id
,
param
)
{
equal
(
id
,
"
2713
"
,
"
put 2713 called
"
);
deepEqual
(
param
,
{
"
foo
"
:
"
bar
"
},
"
put 2713 called
"
);
deepEqual
(
param
,
{
"
foo
"
:
"
bar
"
,
"
title
"
:
"
2713
"
},
"
put 2713 called
"
);
return
id
;
};
...
...
@@ -479,6 +515,39 @@
start
();
});
});
test
(
"
with switchPropertyValue
"
,
function
()
{
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
property
:
{
"
title
"
:
[
"
switchPropertyValue
"
,
[
"
subTitle
"
,
{
"
mytitle
"
:
"
title
"
,
"
yourtitle
"
:
"
othertitle
"
}
]]
},
sub_storage
:
{
type
:
"
mappingstorage2713
"
}
});
Storage2713
.
prototype
.
put
=
function
(
id
,
doc
)
{
equal
(
id
,
"
bar
"
,
"
put 2713 called
"
);
deepEqual
(
doc
,
{
"
subTitle
"
:
"
title
"
},
"
put 2713 called
"
);
return
id
;
};
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
mytitle
"
})
.
push
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// mappingStorage.remove
...
...
@@ -610,7 +679,7 @@
});
});
test
(
"
with equalSubId
mapped
and id in doc
"
,
function
()
{
test
(
"
with equalSubId and id in doc
"
,
function
()
{
stop
();
expect
(
3
);
...
...
@@ -623,7 +692,7 @@
});
Storage2713
.
prototype
.
put
=
function
(
id
,
doc
)
{
deepEqual
(
doc
,
{
"
title
"
:
"
foo
"
},
"
put 2713 called
"
);
deepEqual
(
doc
,
{
"
title
"
:
"
foo
"
,
"
otherId
"
:
"
bar
"
},
"
put 2713 called
"
);
equal
(
id
,
"
bar
"
,
"
put 2713 called
"
);
return
"
bar
"
;
};
...
...
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