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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aurel
jio
Commits
6e12e729
Commit
6e12e729
authored
Jan 25, 2017
by
Vincent Bechu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mappingstorage: add switchPropertyValue mapping function and tests
parent
70c3697f
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 @
6e12e729
...
@@ -119,6 +119,23 @@
...
@@ -119,6 +119,23 @@
doc
[
property
]
=
sub_doc
[
property
];
doc
[
property
]
=
sub_doc
[
property
];
return
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*/
/*jslint unparam: false*/
...
...
test/jio.storage/mappingstorage.tests.js
View file @
6e12e729
...
@@ -280,6 +280,42 @@
...
@@ -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
// mappingStorage.put
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
@@ -373,7 +409,7 @@
...
@@ -373,7 +409,7 @@
Storage2713
.
prototype
.
put
=
function
(
id
,
doc
)
{
Storage2713
.
prototype
.
put
=
function
(
id
,
doc
)
{
deepEqual
(
doc
,
deepEqual
(
doc
,
{
"
otherId
"
:
"
42
"
},
"
post 2713 called
"
);
{
"
otherId
"
:
"
42
"
,
"
title
"
:
"
bar
"
},
"
post 2713 called
"
);
equal
(
id
,
"
bar
"
);
equal
(
id
,
"
bar
"
);
return
"
bar
"
;
return
"
bar
"
;
};
};
...
@@ -404,7 +440,7 @@
...
@@ -404,7 +440,7 @@
Storage2713
.
prototype
.
put
=
function
(
id
,
param
)
{
Storage2713
.
prototype
.
put
=
function
(
id
,
param
)
{
equal
(
id
,
"
2713
"
,
"
put 2713 called
"
);
equal
(
id
,
"
2713
"
,
"
put 2713 called
"
);
deepEqual
(
param
,
{
"
foo
"
:
"
bar
"
},
"
put 2713 called
"
);
deepEqual
(
param
,
{
"
foo
"
:
"
bar
"
,
"
title
"
:
"
2713
"
},
"
put 2713 called
"
);
return
id
;
return
id
;
};
};
...
@@ -479,6 +515,39 @@
...
@@ -479,6 +515,39 @@
start
();
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
// mappingStorage.remove
...
@@ -610,7 +679,7 @@
...
@@ -610,7 +679,7 @@
});
});
});
});
test
(
"
with equalSubId
mapped
and id in doc
"
,
function
()
{
test
(
"
with equalSubId and id in doc
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
...
@@ -623,7 +692,7 @@
...
@@ -623,7 +692,7 @@
});
});
Storage2713
.
prototype
.
put
=
function
(
id
,
doc
)
{
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
"
);
equal
(
id
,
"
bar
"
,
"
put 2713 called
"
);
return
"
bar
"
;
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