Skip to content

Commit c114c06

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 c114c06

5 files changed

Lines changed: 74 additions & 89 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: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)