Repository: DiceDB/dice
File: tests/json_test.go (Go)

Code before:
			name:     "Get Nested Array",
			setCmd:   `JSON.SET inventory $ ` + complexJSON,
			getCmd:   `JSON.GET inventory $.inventory.mountain_bikes[*].model`,
			expected: `["Phoebe","Quaoar","Weywot"]`,
		},
		{
			name:     "Get Nested Object",
			setCmd:   `JSON.SET inventory $ ` + complexJSON,
			getCmd:   `JSON.GET inventory $.inventory.mountain_bikes[0].specs`,
			expected: `{"material":"carbon","weight":13.1}`,
		},
		{
			name:     "Set Nested Value",
			setCmd:   `JSON.SET inventory $.inventory.mountain_bikes[0].price 2000`,
			getCmd:   `JSON.GET inventory $.inventory.mountain_bikes[0].price`,
			expected: `2000`,
		},
	}

	// Multiple test cases will address JSON operations where the order of elements can vary, but all orders are "valid" and to be accepted
	// The variation in order is due to the inherent nature of JSON objects.
	// When dealing with a resultant array that contains elements from multiple objects, the order of these elements can have several valid permutations.
	// Which then means, the overall order of elements in the resultant array is not fixed, although each sub-array within it is guaranteed to be ordered.
	// What goes here:
	// - Cases where the possible order of the resultant array is multiple permutations
	multipleOrderedTestCases := []struct {
		name     string
		setCmd   string
		getCmd   string
		expected []string
	}{
		{
			name:     "Get All Prices",
			setCmd:   `JSON.SET inventory $ ` + complexJSON,
			getCmd:   `JSON.GET inventory $..price`,
			expected: []string{`[1475,3941,1920,2072,3264]`, `[1920,2072,3264,1475,3941]`}, // Ordering agnostic
		},
		{
			name:     "Set Multiple Nested Values",
			setCmd:   `JSON.SET inventory $.inventory.*[?(@.price<2000)].price 1500`,
			getCmd:   `JSON.GET inventory $..price`,
			expected: []string{`[1500,3941,1500,2072,3264]`, `[1500,2072,3264,1500,3941]`}, // Ordering agnostic
		},
	}

	for _, tc := range singleOrderedTestCases {
		t.Run(tc.name, func(t *testing.T) {
			if tc.setCmd != constants.EmptyStr {
				result := fireCommand(conn, tc.setCmd)
				assert.Equal(t, "OK", result)
			}

Review comment (suggestion):
```suggestion
	// - Cases where the possible order of the resultant array is multiple permutations
	// ref: https://github.com/DiceDB/dice/pull/365
```

Code after:
		{
			name:     "Get Nested Array",
			setCmd:   `JSON.SET inventory $ ` + complexJSON,
			getCmd:   `JSON.GET inventory $.inventory.mountain_bikes[*].model`,
			expected: `["Phoebe","Quaoar","Weywot"]`,
		},
		{
			name:     "Get Nested Object",
			setCmd:   `JSON.SET inventory $ ` + complexJSON,
			getCmd:   `JSON.GET inventory $.inventory.mountain_bikes[0].specs`,
			expected: `{"material":"carbon","weight":13.1}`,
		},
		{
			name:     "Set Nested Value",
			setCmd:   `JSON.SET inventory $.inventory.mountain_bikes[0].price 2000`,
			getCmd:   `JSON.GET inventory $.inventory.mountain_bikes[0].price`,
			expected: `2000`,
		},
	}

	// Multiple test cases will address JSON operations where the order of elements can vary, but all orders are "valid" and to be accepted
	// The variation in order is due to the inherent nature of JSON objects.
	// When dealing with a resultant array that contains elements from multiple objects, the order of these elements can have several valid permutations.
	// Which then means, the overall order of elements in the resultant array is not fixed, although each sub-array within it is guaranteed to be ordered.
	// What goes here:
	// - Cases where the possible order of the resultant array is multiple permutations
	// ref: https://github.com/DiceDB/dice/pull/365
	multipleOrderedTestCases := []struct {
		name     string
		setCmd   string
		getCmd   string
		expected []string
	}{
		{
			name:     "Get All Prices",
			setCmd:   `JSON.SET inventory $ ` + complexJSON,
			getCmd:   `JSON.GET inventory $..price`,
			expected: []string{`[1475,3941,1920,2072,3264]`, `[1920,2072,3264,1475,3941]`}, // Ordering agnostic
		},
		{
			name:     "Set Multiple Nested Values",
			setCmd:   `JSON.SET inventory $.inventory.*[?(@.price<2000)].price 1500`,
			getCmd:   `JSON.GET inventory $..price`,
			expected: []string{`[1500,3941,1500,2072,3264]`, `[1500,2072,3264,1500,3941]`}, // Ordering agnostic
		},
	}

	for _, tc := range singleOrderedTestCases {
		t.Run(tc.name, func(t *testing.T) {
			if tc.setCmd != constants.EmptyStr {
				result := fireCommand(conn, tc.setCmd)