Skip to content

Commit c7d72b8

Browse files
committed
Refactor Parse Server startup and LiveQuery test setup
Moved Parse Server configuration to environment variables in the startup script and simplified server invocation. Updated LiveQuery integration test to use block-based configuration and improved setup/teardown for better test isolation.
1 parent 0f4eacc commit c7d72b8

5 files changed

Lines changed: 88 additions & 93 deletions

scripts/start-parse.sh

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ set -e
44
echo "=== Parse Server Startup Script ==="
55
echo "Setting up environment..."
66

7-
# Write environment variables to a file for debugging
8-
echo "PARSE_SERVER_MASTER_KEY_IPS=0.0.0.0/0,::/0" >> /tmp/parse-env
9-
echo "Environment file contents:"
10-
cat /tmp/parse-env
11-
12-
# Export the environment variable
7+
# Export environment variables for Parse Server
138
export PARSE_SERVER_MASTER_KEY_IPS="0.0.0.0/0,::/0"
9+
export PARSE_SERVER_APPLICATION_ID="myAppId"
10+
export PARSE_SERVER_MASTER_KEY="myMasterKey"
11+
export PARSE_SERVER_REST_API_KEY="test-rest-key"
12+
export PARSE_SERVER_DATABASE_URI="mongodb://admin:password@mongo:27017/parse?authSource=admin"
13+
export PARSE_SERVER_MOUNT_PATH="/parse"
14+
export PARSE_SERVER_CLOUD="/parse-server/cloud/main.js"
15+
export PARSE_SERVER_LOG_LEVEL="info"
16+
export PARSE_SERVER_ALLOW_CLIENT_CLASS_CREATION="true"
17+
18+
# LiveQuery configuration via environment variables
19+
export PARSE_SERVER_LIVE_QUERY='{"classNames":["Song","Album","User","_User","TestLiveQuery"]}'
20+
export PARSE_SERVER_START_LIVE_QUERY_SERVER="true"
1421

15-
# Verify the variable is set
16-
echo "Environment variable check:"
17-
echo "PARSE_SERVER_MASTER_KEY_IPS: $PARSE_SERVER_MASTER_KEY_IPS"
22+
echo "Environment configured:"
23+
echo " PARSE_SERVER_APPLICATION_ID: $PARSE_SERVER_APPLICATION_ID"
24+
echo " PARSE_SERVER_LIVE_QUERY: $PARSE_SERVER_LIVE_QUERY"
25+
echo " PARSE_SERVER_START_LIVE_QUERY_SERVER: $PARSE_SERVER_START_LIVE_QUERY_SERVER"
1826

1927
# Start Parse Server
2028
echo "Starting Parse Server..."
@@ -23,48 +31,15 @@ echo "Looking for parse-server..."
2331
which node
2432
ls -la /parse-server/
2533

26-
# LiveQuery classes to enable real-time updates
27-
LIVE_QUERY_CLASSES="Song,Album,User,_User,TestLiveQuery"
28-
2934
# Try different ways to start parse-server
3035
if [ -f "/parse-server/bin/parse-server" ]; then
3136
echo "Using /parse-server/bin/parse-server"
32-
exec /parse-server/bin/parse-server \
33-
--appId myAppId \
34-
--masterKey myMasterKey \
35-
--restAPIKey test-rest-key \
36-
--databaseURI mongodb://admin:password@mongo:27017/parse?authSource=admin \
37-
--mountPath /parse \
38-
--cloud /parse-server/cloud/main.js \
39-
--logLevel info \
40-
--allowClientClassCreation true \
41-
--liveQuery.classNames "$LIVE_QUERY_CLASSES" \
42-
--startLiveQueryServer true
37+
exec /parse-server/bin/parse-server
4338
elif [ -f "/usr/src/app/bin/parse-server" ]; then
4439
echo "Using /usr/src/app/bin/parse-server"
45-
exec /usr/src/app/bin/parse-server \
46-
--appId myAppId \
47-
--masterKey myMasterKey \
48-
--restAPIKey test-rest-key \
49-
--databaseURI mongodb://admin:password@mongo:27017/parse?authSource=admin \
50-
--mountPath /parse \
51-
--cloud /parse-server/cloud/main.js \
52-
--logLevel info \
53-
--allowClientClassCreation true \
54-
--liveQuery.classNames "$LIVE_QUERY_CLASSES" \
55-
--startLiveQueryServer true
40+
exec /usr/src/app/bin/parse-server
5641
else
5742
echo "Trying with node and index.js"
5843
cd /parse-server
59-
exec node ./bin/parse-server \
60-
--appId myAppId \
61-
--masterKey myMasterKey \
62-
--restAPIKey test-rest-key \
63-
--databaseURI mongodb://admin:password@mongo:27017/parse?authSource=admin \
64-
--mountPath /parse \
65-
--cloud /parse-server/cloud/main.js \
66-
--logLevel info \
67-
--allowClientClassCreation true \
68-
--liveQuery.classNames "$LIVE_QUERY_CLASSES" \
69-
--startLiveQueryServer true
44+
exec node ./bin/parse-server
7045
fi

test/lib/parse/hooks_and_validation_integration_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class TestProduct < Parse::Object
3030
validate :custom_sku_format
3131

3232
def custom_sku_format
33-
if sku.present? && !sku.match?(/^[A-Z]{3}-\d{4}$/)
33+
# Allow both upper and lowercase since normalize_data will uppercase it
34+
if sku.present? && !sku.match?(/^[A-Za-z]{3}-\d{4}$/)
3435
errors.add(:sku, "must be in format XXX-0000 (e.g., ABC-1234)")
3536
end
3637
end

test/lib/parse/live_query_integration_test.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# frozen_string_literal: true
33

44
require_relative "../../test_helper_integration"
5+
require_relative "../../../lib/parse/live_query"
56

67
# Define a test model for LiveQuery integration tests
78
class TestLiveQueryModel < Parse::Object
@@ -17,14 +18,18 @@ class LiveQueryIntegrationTest < Minitest::Test
1718
LIVE_QUERY_URL = "ws://localhost:2337"
1819

1920
def setup
20-
super
21+
# Setup Parse client connection first (this is normally done by the module)
22+
Parse::Test::ServerHelper.setup
23+
24+
# Enable LiveQuery feature
25+
Parse.live_query_enabled = true
2126

2227
# Configure LiveQuery
23-
Parse::LiveQuery.configure(
24-
url: LIVE_QUERY_URL,
25-
application_id: "myAppId",
26-
client_key: "test-rest-key",
27-
)
28+
Parse::LiveQuery.configure do |config|
29+
config.url = LIVE_QUERY_URL
30+
config.application_id = "myAppId"
31+
config.client_key = "test-rest-key"
32+
end
2833

2934
# Clean up any existing test data
3035
cleanup_test_objects
@@ -33,7 +38,6 @@ def setup
3338
def teardown
3439
Parse::LiveQuery.reset!
3540
cleanup_test_objects
36-
super
3741
end
3842

3943
def cleanup_test_objects

test/lib/parse/model_associations_integration_test.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AssociationTestBook < Parse::Object
3030

3131
# Belongs to association
3232
belongs_to :author, as: :association_test_author
33-
belongs_to :publisher, required: true
33+
belongs_to :publisher, as: :association_test_publisher, required: true
3434
end
3535

3636
class AssociationTestPublisher < Parse::Object
@@ -468,6 +468,10 @@ def test_has_many_array_pointer_collections
468468
# Test 1: Set up data for array pointer collections
469469
puts "\n--- Test 1: Setting up data for array pointer collections ---"
470470

471+
# Create publisher for books (publisher is required)
472+
publisher = AssociationTestPublisher.new(name: "Array Test Publisher", country: "USA")
473+
assert publisher.save, "Publisher should save successfully"
474+
471475
# Create authors
472476
author1 = AssociationTestAuthor.new(name: "Array Author 1", email: "array1@example.com")
473477
author2 = AssociationTestAuthor.new(name: "Array Author 2", email: "array2@example.com")
@@ -478,9 +482,9 @@ def test_has_many_array_pointer_collections
478482
assert author3.save, "Author 3 should save successfully"
479483

480484
# Create books
481-
book1 = AssociationTestBook.new(title: "Array Book 1", author: author1)
482-
book2 = AssociationTestBook.new(title: "Array Book 2", author: author2)
483-
book3 = AssociationTestBook.new(title: "Array Book 3", author: author3)
485+
book1 = AssociationTestBook.new(title: "Array Book 1", author: author1, publisher: publisher)
486+
book2 = AssociationTestBook.new(title: "Array Book 2", author: author2, publisher: publisher)
487+
book3 = AssociationTestBook.new(title: "Array Book 3", author: author3, publisher: publisher)
484488

485489
assert book1.save, "Book 1 should save successfully"
486490
assert book2.save, "Book 2 should save successfully"
@@ -862,6 +866,10 @@ def test_association_edge_cases_and_error_handling
862866
# Test 5: Test association queries with edge case data
863867
puts "\n--- Test 5: Testing association queries with edge case data ---"
864868

869+
# Create publisher for edge case tests
870+
edge_publisher = AssociationTestPublisher.new(name: "Edge Publisher", country: "USA")
871+
assert edge_publisher.save, "Edge publisher should save"
872+
865873
# Create author with special characters
866874
special_author = AssociationTestAuthor.new(
867875
name: "Special Author àáâãäå",
@@ -873,6 +881,7 @@ def test_association_edge_cases_and_error_handling
873881
special_book = AssociationTestBook.new(
874882
title: "Special Title: Ñoël & Company",
875883
author: special_author,
884+
publisher: edge_publisher,
876885
price: 99.99,
877886
)
878887
assert special_book.save, "Special character book should save"
@@ -899,11 +908,12 @@ def test_association_edge_cases_and_error_handling
899908
perf_author = AssociationTestAuthor.new(name: "Performance Author")
900909
assert perf_author.save, "Performance author should save"
901910

902-
# Create multiple books quickly
911+
# Create multiple books quickly (reusing edge_publisher from above)
903912
(1..10).each do |i|
904913
book = AssociationTestBook.new(
905914
title: "Performance Book #{i}",
906915
author: perf_author,
916+
publisher: edge_publisher,
907917
price: i * 10.0,
908918
)
909919
assert book.save, "Performance book #{i} should save"

0 commit comments

Comments
 (0)