From 63dd2afb0974650cd8fdbcad84dc81c68f0302d2 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Thu, 20 Apr 2017 10:52:25 +0000
Subject: [PATCH] SSDM-4925: Test 'searchSamples() withoutSpace' modified by
 creating, searching and deleting a shared sample. MASTER_PLATE example of a
 shared sample removed from test database.

SVN: 38072
---
 .../html/test/test-search.js                  | 58 +++++++++++++++----
 .../db/openbis_test_js_common.sql             |  1 -
 2 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-search.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-search.js
index fc7d168fe87..701ad13cd92 100644
--- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-search.js
+++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-search.js
@@ -375,18 +375,52 @@ define([ 'jquery', 'underscore', 'openbis', 'test/openbis-execute-operations', '
 
 		QUnit.test("searchSamples() withoutSpace", function(assert) {
 			var c = new common(assert, openbis);
-
-			var fSearch = function(facade) {
-				var criteria = new c.SampleSearchCriteria();
-				criteria.withoutSpace();
-				return facade.searchSamples(criteria, c.createSampleFetchOptions());
-			}
-
-			var fCheck = function(facade, samples) {
-				c.assertObjectsWithValues(samples, "identifier", [ "/MASTER_PLATE" ]);
-			}
-
-			testSearch(c, fSearch, fCheck);
+			var code = c.generateId("SAMPLE");
+			var waitUntilIndexed = function(facade, samplePermId, timeout, action) {
+				if (timeout < 0) {
+					c.fail("Sample " + samplePermId + " after " + timeout + " msec.");
+				}
+				setTimeout(function() {
+					c.ok("Wait until " + samplePermId + " indexed. " + timeout);
+					var criteria = new c.SampleSearchCriteria();
+					criteria.withPermId().thatEquals(samplePermId);
+					facade.searchSamples(criteria, c.createSampleFetchOptions()).then(function(result) {
+						if (result.getTotalCount() == 0) {
+							waitUntilIndexed(facade, samplePermId, timeout - 1000, action);
+						} else {
+							action();
+						}
+					});
+				}, 1000)
+			};
+			
+			c.start();
+			c.createFacadeAndLogin().then(function(facade) {
+				c.ok("Login");
+				var creation = new c.SampleCreation();
+				creation.setTypeId(new c.EntityTypePermId("UNKNOWN"));
+				creation.setCode(code);
+				facade.createSamples([ creation ]).then(function(permIds) {
+					var permId = permIds[0];
+					c.ok("Shared sample created: " + permId);
+					waitUntilIndexed(facade, permId.getPermId(), 10000, function() {
+						var criteria = new c.SampleSearchCriteria();
+						criteria.withoutSpace();
+						facade.searchSamples(criteria, c.createSampleFetchOptions()).then(function(results) {
+							c.ok("Got results");
+							var samples = results.getObjects();
+							c.assertObjectsWithValues(samples, "identifier", [ "/" + code ]);
+							c.deleteSample(facade, permId).then(function() {
+								c.ok("Sample " + permId + " trashed");
+								c.finish();
+							});
+						});
+					});
+				});
+			}).fail(function(error) {
+				c.fail(error.message);
+				c.finish();
+			});
 		});
 		
 		QUnit.test("searchSamples() withoutExperiment", function(assert) {
diff --git a/js-test/servers/common/openBIS-server/db/openbis_test_js_common.sql b/js-test/servers/common/openBIS-server/db/openbis_test_js_common.sql
index 7230f34c4f1..a13ad576a00 100644
--- a/js-test/servers/common/openBIS-server/db/openbis_test_js_common.sql
+++ b/js-test/servers/common/openBIS-server/db/openbis_test_js_common.sql
@@ -7180,7 +7180,6 @@ COPY samples_all (id, perm_id, code, expe_id, saty_id, registration_timestamp, m
 351	20130424134657597-433	TEST-SAMPLE-1	\N	1	2013-04-24 13:46:57.422371+02	2013-04-24 13:47:42.541+02	3	\N	\N	3	\N	3	TEST-SAMPLE-1,-1,3	\N	0	\N
 345	20130415091923485-402	TEST-SAMPLE-2	6	1	2013-04-15 09:19:23.189016+02	2013-04-24 14:50:08.09+02	3	\N	\N	3	\N	4	TEST-SAMPLE-2,-1,3	\N	17	\N
 2	20130412140147735-20	PLATE-1	2	11	2013-04-12 14:01:43.729885+02	2013-05-15 15:20:29.57+02	3	\N	\N	2	\N	3	PLATE-1,-1,2	\N	42	\N
-1	20130412140147740-1	MASTER_PLATE	\N	11	2013-04-12 14:01:43.729885+02	2013-05-15 15:20:29.57+02	3	\N	\N	\N	\N	3	PLATE-1,-1,2	\N	42	\N
 \.
 
 
-- 
GitLab