Skip to content
Snippets Groups Projects
Commit d56d1e14 authored by pkupczyk's avatar pkupczyk
Browse files

SSDM-2005 : V3 AS API - JS tests - more sample tests

SVN: 34263
parent 65e1407f
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,14 @@ define([ 'jquery', 'openbis' ], function($, openbis) { ...@@ -34,6 +34,14 @@ define([ 'jquery', 'openbis' ], function($, openbis) {
return dfd.promise(); return dfd.promise();
}; };
this.getObjectProperty = function(object, propertyName) {
var propertyNames = propertyName.split('.');
for ( var pn in propertyNames) {
object = object[propertyNames[pn]];
}
return object;
};
this.createFacade = function(action) { this.createFacade = function(action) {
var facade = new openbis(testApiUrl); var facade = new openbis(testApiUrl);
action(facade); action(facade);
...@@ -224,6 +232,20 @@ define([ 'jquery', 'openbis' ], function($, openbis) { ...@@ -224,6 +232,20 @@ define([ 'jquery', 'openbis' ], function($, openbis) {
this.assertEqual(objects.length, count, 'Got ' + count + ' object(s)'); this.assertEqual(objects.length, count, 'Got ' + count + ' object(s)');
}; };
this.assertObjectsWithValues = function(objects, propertyName, propertyValues) {
var thisCommon = this;
var values = {};
$.each(objects, function(index, object) {
var value = thisCommon.getObjectProperty(object, propertyName);
if (value in values == false) {
values[value] = true;
}
});
this.assert.deepEqual(Object.keys(values).sort(), propertyValues.sort(), 'Objects have correct ' + propertyName + ' values')
};
this.assertObjectsWithOrWithoutCollections = function(objects, accessor, checker) { this.assertObjectsWithOrWithoutCollections = function(objects, accessor, checker) {
var theObjects = null; var theObjects = null;
......
...@@ -22,7 +22,7 @@ define([ 'jquery', 'underscore', 'openbis', 'test/common', 'dto/entity/experimen ...@@ -22,7 +22,7 @@ define([ 'jquery', 'underscore', 'openbis', 'test/common', 'dto/entity/experimen
c.assertEqual(experiment.getProject().getSpace().getCode(), "PLATONIC", "Space code"); c.assertEqual(experiment.getProject().getSpace().getCode(), "PLATONIC", "Space code");
done(); done();
}).fail(function(error) { }).fail(function(error) {
f.fail(error.message); c.fail(error.message);
done(); done();
}); });
}); });
......
define([ 'jquery', 'openbis', 'test/common', 'dto/entity/sample/SampleCreation', 'dto/id/entitytype/EntityTypePermId', 'dto/id/space/SpacePermId', 'dto/id/tag/TagCode' ], function($, openbis, common, define([ 'jquery', 'openbis', 'test/common', 'dto/entity/sample/SampleCreation', 'dto/entity/sample/SampleUpdate', 'dto/id/entitytype/EntityTypePermId', 'dto/id/space/SpacePermId',
SampleCreation, EntityTypePermId, SpacePermId, TagCode) { 'dto/id/tag/TagCode' ], function($, openbis, common, SampleCreation, SampleUpdate, EntityTypePermId, SpacePermId, TagCode) {
return function() { return function() {
QUnit.module("Sample tests"); QUnit.module("Sample tests");
...@@ -42,7 +42,7 @@ define([ 'jquery', 'openbis', 'test/common', 'dto/entity/sample/SampleCreation', ...@@ -42,7 +42,7 @@ define([ 'jquery', 'openbis', 'test/common', 'dto/entity/sample/SampleCreation',
QUnit.test("searchSamples()", function(assert) { QUnit.test("searchSamples()", function(assert) {
var c = new common(assert); var c = new common(assert);
var done = assert.async(); var done = assert.async();
$.when(c.createFacadeAndLogin(), c.createSampleSearchCriterion(), c.createSampleFetchOptions()).then(function(facade, criterion, fetchOptions) { $.when(c.createFacadeAndLogin(), c.createSampleSearchCriterion(), c.createSampleFetchOptions()).then(function(facade, criterion, fetchOptions) {
criterion.withCode().thatEquals("PLATE-1"); criterion.withCode().thatEquals("PLATE-1");
...@@ -98,40 +98,47 @@ define([ 'jquery', 'openbis', 'test/common', 'dto/entity/sample/SampleCreation', ...@@ -98,40 +98,47 @@ define([ 'jquery', 'openbis', 'test/common', 'dto/entity/sample/SampleCreation',
}); });
}); });
/* QUnit.test("updateSamples()", function(assert) {
* test("updateSamples()", function() { var code = "UPDATE_JSON_SAMPLE_" + var c = new common(assert);
* (new Date().getTime()); var done = assert.async();
*
* createFacadeAndLogin().then(function(facade) { var creations = [ { var creation = new SampleCreation();
* "@type" : "SampleCreation", creation.setTypeId(new EntityTypePermId("UNKNOWN"));
* creation.setCode("CREATE_JSON_SAMPLE_" + (new Date().getTime()));
* "typeId" : { "@type" : "EntityTypePermId", "permId" : "UNKNOWN" }, creation.setSpaceId(new SpacePermId("TEST"));
* creation.setTagIds([ new TagCode("CREATE_JSON_TAG") ]);
* "code" : code,
* $.when(c.createFacadeAndLogin(), c.createSampleFetchOptions()).then(function(facade, fetchOptions) {
* "spaceId" : { "@type" : "SpacePermId", "permId" : "PLATONIC" } } ]; return facade.createSamples([ creation ]).then(function(permIds) {
*
* var ids = facade.createSamples(creations).then(function(permIds) { var update = new SampleUpdate();
* var updates = [ { "@type" : "SampleUpdate", update.setSampleId(permIds[0]);
* update.getTagIds().remove(new TagCode("CREATE_JSON_TAG"));
* "sampleId" : permIds[0], update.getTagIds().add(new TagCode("CREATE_JSON_TAG_2"));
* update.getTagIds().add(new TagCode("CREATE_JSON_TAG_3"));
* "spaceId" : { "@type" : "SpacePermId", "permId" : "TEST" } } ];
* return facade.updateSamples([ update ]).then(function() {
* return facade.updateSamples(updates).then(function() { return return facade.mapSamples(permIds, fetchOptions).done(function() {
* permIds; }); }); facade.logout();
* })
* return $.when(ids, createSampleFetchOptions()).then(function(permIds, });
* fetchOptions) { return facade.mapSamples(permIds, })
* fetchOptions).done(function() { facade.logout(); }) }) }).done(function(samples) {
* }).done(function(samples) { var keys = Object.keys(samples); var keys = Object.keys(samples);
* assertObjectsCount(keys, 1); c.assertObjectsCount(keys, 1);
*
* var sample = samples[keys[0]]; equal(sample.code, code, "Sample var sample = samples[keys[0]];
* code"); equal(sample.type.code, "UNKNOWN", "Type code"); c.assertEqual(sample.getCode(), creation.getCode(), "Sample code");
* equal(sample.space.code, "TEST", "Space code"); start(); c.assertEqual(sample.getType().getCode(), creation.getTypeId().getPermId(), "Type code");
* }).fail(function(error) { ok(false, error.message); start(); }); }); c.assertEqual(sample.getSpace().getCode(), creation.getSpaceId().getPermId(), "Space code");
*/ c.assertObjectsCount(sample.getTags(), 2);
c.assertObjectsWithValues(sample.getTags(), "code", [ "CREATE_JSON_TAG_2", "CREATE_JSON_TAG_3" ]);
done();
}).fail(function(error) {
c.fail(error.message);
done();
});
});
} }
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment