firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.13k stars 242 forks source link

Typo in AndroidNotification unmarshal #434

Closed parnic closed 3 years ago

parnic commented 3 years ago

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)
        }
    }
}
hiranya911 commented 3 years ago

Thanks for the fix.