Skip to content

Typo in AndroidNotification unmarshal #434

Description

@parnic
  • Firebase SDK version: 4.5.0
  • Library version: latest
  • Firebase Product: messaging

Steps to reproduce:

Attempt to unmarshal/deserialize a message with the PRIORITY_DEFAULT priority.

Relevant Code:

From the SDK:

	if temp.Priority != "" {
		priorities := map[string]AndroidNotificationPriority{
			"PRIORITY_MIN":     PriorityMin,
			"PRIORITY_LOW":     PriorityLow,
			"PRIORITY_DEFUALT": PriorityDefault,
			"PRIORITY_HIGH":    PriorityHigh,
			"PRIORITY_MAX":     PriorityMax,
		}
		if prio, ok := priorities[temp.Priority]; ok {
			a.Priority = prio
		} else {
			return fmt.Errorf("unknown priority value: %q", temp.Priority)
		}
	}

To trigger:

var validMessages = []struct {
	name string
	req  *Message
	want map[string]interface{}
}{
	{
		name: "AndroidNotificationPriorityDefault",
		req: &Message{
			Android: &AndroidConfig{
				Notification: &AndroidNotification{
					Priority: PriorityDefault,
				},
			},
			Topic: "test-topic",
		},
		want: map[string]interface{}{
			"android": map[string]interface{}{
				"notification": map[string]interface{}{
					"notification_priority": "PRIORITY_DEFAULT",
				},
			},
			"topic": "test-topic",
		},
	},
}

func TestJSONUnmarshal(t *testing.T) {
	for _, tc := range validMessages {
		b, err := json.Marshal(tc.req)
		if err != nil {
			t.Errorf("Marshal(%s) = %v; want = nil", tc.name, err)
		}
		var target Message
		if err := json.Unmarshal(b, &target); err != nil {
			t.Errorf("Unmarshal(%s) = %v; want = nil", tc.name, err)
		}
		if !reflect.DeepEqual(tc.req, &target) {
			t.Errorf("Unmarshal(%s) result = %#v; want = %#v", tc.name, tc.req, target)
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions