-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Firebase Cloud Messaging #62
Merged
Merged
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f6208a4
initial commit for adding Firebase Cloud Messaging
chemidy 0759106
add validator
chemidy 049c425
Merge remote-tracking branch 'upstream/dev' into fcm
chemidy a0ba55c
use http const in messaging test
chemidy c40516b
add client version header for stats
chemidy c91fb40
init integration test
chemidy d312b7c
add integration test (validated on IOS today)
0e83458
add comment with URL to enable Firebase Cloud Messaging API
94cd35e
fix broken test
chemidy 6d76105
add integration tests
chemidy 4e24472
Merge branch 'dev' into fcm
chemidy aee449c
accept a Message instead of RequestMessage + and rename method + send…
chemidy 4b37eee
Merge branch 'dev' into fcm
chemidy 642de9f
Merge branch 'dev' into fcm
chemidy 3c6dbcf
Merge remote-tracking branch 'upstream/dev' into fcm
chemidy 746bfb7
update fcm url
chemidy 8a58a72
rollback url endpoint
chemidy 78303e6
Merge remote-tracking branch 'upstream/dev' into fcm
c72d90f
fix http constants, change responseMessage visibility, change map[str…
7091e4b
fix http constants
06195be
fix integration tests
8b2f6bf
fix APNS naming
chemidy cb9e342
Merge branch 'dev' into fcm
chemidy 0802b84
Merge branch 'dev' into fcm
chemidy 24bdea0
add validators
chemidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,338 @@ | ||
package messaging | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"firebase.google.com/go/integration/internal" | ||
"firebase.google.com/go/messaging" | ||
) | ||
|
||
var projectID string | ||
var client *messaging.Client | ||
|
||
var testFixtures = struct { | ||
token string | ||
topic string | ||
condition string | ||
}{} | ||
|
||
// Enable API before testing | ||
// https://console.developers.google.com/apis/library/fcm.googleapis.com/?project= | ||
func TestMain(m *testing.M) { | ||
flag.Parse() | ||
if testing.Short() { | ||
log.Println("skipping Messaging integration tests in short mode.") | ||
return | ||
} | ||
|
||
token, err := ioutil.ReadFile(internal.Resource("integration_token.txt")) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
testFixtures.token = string(token) | ||
|
||
topic, err := ioutil.ReadFile(internal.Resource("integration_topic.txt")) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
testFixtures.topic = string(topic) | ||
|
||
condition, err := ioutil.ReadFile(internal.Resource("integration_condition.txt")) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
testFixtures.condition = string(condition) | ||
|
||
ctx := context.Background() | ||
app, err := internal.NewTestApp(ctx) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
projectID, err = internal.ProjectID() | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
client, err = app.Messaging(ctx) | ||
|
||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func TestSendMessageInvalidToken(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
Message: messaging.Message{ | ||
Token: "INVALID_TOKEN", | ||
Notification: messaging.Notification{ | ||
Title: "My Title", | ||
Body: "This is a Notification", | ||
}, | ||
}, | ||
} | ||
_, err := client.SendMessage(ctx, msg) | ||
|
||
if err == nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func TestSendMessageValidateOnly(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
ValidateOnly: true, | ||
Message: messaging.Message{ | ||
Token: testFixtures.token, | ||
Notification: messaging.Notification{ | ||
Title: "My Title", | ||
Body: "This is a Notification", | ||
}, | ||
}, | ||
} | ||
resp, err := client.SendMessage(ctx, msg) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if resp.Name != fmt.Sprintf("projects/%s/messages/fake_message_id", projectID) { | ||
t.Errorf("Name : %s; want : projects/%s/messages/fake_message_id", resp.Name, projectID) | ||
} | ||
} | ||
|
||
func TestSendMessageToToken(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
Message: messaging.Message{ | ||
Token: testFixtures.token, | ||
Notification: messaging.Notification{ | ||
Title: "My Title", | ||
Body: "This is a Notification", | ||
}, | ||
}, | ||
} | ||
resp, err := client.SendMessage(ctx, msg) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if resp.Name == "" { | ||
t.Errorf("Name : %s; want : projects/%s/messages/#id#", resp.Name, projectID) | ||
} | ||
} | ||
|
||
func TestSendMessageToTopic(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
Message: messaging.Message{ | ||
Topic: testFixtures.topic, | ||
Notification: messaging.Notification{ | ||
Title: "My Title", | ||
Body: "This is a Notification", | ||
}, | ||
}, | ||
} | ||
resp, err := client.SendMessage(ctx, msg) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if resp.Name == "" { | ||
t.Errorf("Name : %s; want : projects/%s/messages/#id#", resp.Name, projectID) | ||
} | ||
} | ||
|
||
func TestSendMessageToCondition(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
Message: messaging.Message{ | ||
Condition: testFixtures.condition, | ||
Notification: messaging.Notification{ | ||
Title: "My Title", | ||
Body: "This is a Notification", | ||
}, | ||
}, | ||
} | ||
resp, err := client.SendMessage(ctx, msg) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if resp.Name == "" { | ||
t.Errorf("Name : %s; want : projects/%s/messages/#id#", resp.Name, projectID) | ||
} | ||
} | ||
|
||
func TestSendNotificationMessage(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
Message: messaging.Message{ | ||
Token: testFixtures.token, | ||
Notification: messaging.Notification{ | ||
Title: "My Title", | ||
Body: "This is a Notification", | ||
}, | ||
}, | ||
} | ||
resp, err := client.SendMessage(ctx, msg) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if resp.Name == "" { | ||
t.Errorf("Name : %s; want : projects/%s/messages/#id#", resp.Name, projectID) | ||
} | ||
} | ||
|
||
func TestSendDataMessage(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
Message: messaging.Message{ | ||
Token: testFixtures.token, | ||
Data: map[string]interface{}{ | ||
"private_key": "foo", | ||
"client_email": "bar@test.com", | ||
}, | ||
}, | ||
} | ||
resp, err := client.SendMessage(ctx, msg) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if resp.Name == "" { | ||
t.Errorf("Name : %s; want : projects/%s/messages/#id#", resp.Name, projectID) | ||
} | ||
} | ||
|
||
func TestSendAndroidNotificationMessage(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
Message: messaging.Message{ | ||
Token: testFixtures.token, | ||
Notification: messaging.Notification{ | ||
Title: "My Title", | ||
Body: "This is a Notification", | ||
}, | ||
Android: messaging.AndroidConfig{ | ||
CollapseKey: "Collapse", | ||
Priority: "HIGH", | ||
TTL: "3.5s", | ||
Notification: messaging.AndroidNotification{ | ||
Title: "Android Title", | ||
Body: "Android body", | ||
}, | ||
}, | ||
}, | ||
} | ||
resp, err := client.SendMessage(ctx, msg) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if resp.Name == "" { | ||
t.Errorf("Name : %s; want : projects/%s/messages/#id#", resp.Name, projectID) | ||
} | ||
} | ||
|
||
func TestSendAndroidDataMessage(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
Message: messaging.Message{ | ||
Token: testFixtures.token, | ||
Notification: messaging.Notification{ | ||
Title: "My Title", | ||
Body: "This is a Notification", | ||
}, | ||
Android: messaging.AndroidConfig{ | ||
CollapseKey: "Collapse", | ||
Priority: "HIGH", | ||
TTL: "3.5s", | ||
Data: map[string]interface{}{ | ||
"private_key": "foo", | ||
"client_email": "bar@test.com", | ||
}, | ||
}, | ||
}, | ||
} | ||
resp, err := client.SendMessage(ctx, msg) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if resp.Name == "" { | ||
t.Errorf("Name : %s; want : projects/%s/messages/#id#", resp.Name, projectID) | ||
} | ||
} | ||
|
||
func TestSendApnsNotificationMessage(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
Message: messaging.Message{ | ||
Token: testFixtures.token, | ||
Notification: messaging.Notification{ | ||
Title: "My Title", | ||
Body: "This is a Notification", | ||
}, | ||
Apns: messaging.ApnsConfig{ | ||
Payload: map[string]interface{}{ | ||
"title": "APNS Title ", | ||
"body": "APNS bodym", | ||
}, | ||
}, | ||
}, | ||
} | ||
resp, err := client.SendMessage(ctx, msg) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if resp.Name == "" { | ||
t.Errorf("Name : %s; want : projects/%s/messages/#id#", resp.Name, projectID) | ||
} | ||
} | ||
|
||
func TestSendApnsDataMessage(t *testing.T) { | ||
ctx := context.Background() | ||
msg := &messaging.RequestMessage{ | ||
Message: messaging.Message{ | ||
Token: testFixtures.token, | ||
Notification: messaging.Notification{ | ||
Title: "My Title", | ||
Body: "This is a Notification", | ||
}, | ||
Apns: messaging.ApnsConfig{ | ||
Headers: map[string]interface{}{ | ||
"private_key": "foo", | ||
"client_email": "bar@test.com", | ||
}, | ||
}, | ||
}, | ||
} | ||
resp, err := client.SendMessage(ctx, msg) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if resp.Name == "" { | ||
t.Errorf("Name : %s; want : projects/%s/messages/#id#", resp.Name, projectID) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these files require a lot of setting up. Lets keep this simple by doing something like: https://github.com/firebase/firebase-admin-java/blob/a4661a0f44d1dc35d1531eac78f9e3459d6bccb7/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java