-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12f6871
commit a11b478
Showing
11 changed files
with
173 additions
and
59 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Service Level Variables | ||
|
||
SERVICE_NAME=notifications |
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,8 @@ | ||
DB_NAME=dydx_dev | ||
DB_USERNAME=dydx_dev | ||
DB_PASSWORD=dydxserver123 | ||
PG_POOL_MAX=2 | ||
PG_POOL_MIN=1 | ||
DB_HOSTNAME=postgres | ||
DB_READONLY_HOSTNAME=postgres | ||
DB_PORT=5432 |
Empty file.
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,10 @@ | ||
SERVICE_NAME=notifications | ||
|
||
FIREBASE_PROJECT_ID=projectID | ||
FIREBASE_PRIVATE_KEY='-----BEGIN RSA PRIVATE KEY----------END RSA PRIVATE KEY-----' | ||
FIREBASE_CLIENT_EMAIL=[email protected] | ||
|
||
DB_NAME=dydx_test | ||
DB_USERNAME=dydx_test | ||
DB_PASSWORD=dydxserver123 | ||
DB_PORT=5436 |
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,73 @@ | ||
import { logger } from '@dydxprotocol-indexer/base'; | ||
import { sendFirebaseMessage } from '../src/message'; | ||
import { sendMulticast } from '../src/lib/firebase'; | ||
import { createNotification, NotificationType } from '../src/types'; | ||
import { testMocks, dbHelpers } from '@dydxprotocol-indexer/postgres'; | ||
import { defaultToken } from '@dydxprotocol-indexer/postgres/build/__tests__/helpers/constants'; | ||
|
||
jest.mock('../src/lib/firebase', () => ({ | ||
sendMulticast: jest.fn(), | ||
})); | ||
|
||
describe('sendFirebaseMessage', () => { | ||
let loggerInfoSpy: jest.SpyInstance; | ||
let loggerWarnSpy: jest.SpyInstance; | ||
let loggerErrorSpy: jest.SpyInstance; | ||
|
||
beforeAll(() => { | ||
loggerInfoSpy = jest.spyOn(logger, 'info').mockImplementation(); | ||
loggerWarnSpy = jest.spyOn(logger, 'warning').mockImplementation(); | ||
loggerErrorSpy = jest.spyOn(logger, 'error').mockImplementation(); | ||
}); | ||
|
||
afterAll(() => { | ||
loggerInfoSpy.mockRestore(); | ||
loggerWarnSpy.mockRestore(); | ||
loggerErrorSpy.mockRestore(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await testMocks.seedData(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await dbHelpers.clearData(); | ||
}); | ||
|
||
const mockNotification = createNotification(NotificationType.ORDER_FILLED, { | ||
AMOUNT: '10', | ||
MARKET: 'BTC-USD', | ||
AVERAGE_PRICE: '100.50', | ||
}); | ||
|
||
it('should send a Firebase message successfully', async () => { | ||
await sendFirebaseMessage([defaultToken.token], mockNotification); | ||
|
||
expect(sendMulticast).toHaveBeenCalled(); | ||
expect(logger.info).toHaveBeenCalledWith(expect.objectContaining({ | ||
message: 'Firebase message sent successfully', | ||
notificationType: mockNotification.type, | ||
})); | ||
}); | ||
|
||
it('should log a warning if user has no registration tokens', async () => { | ||
await sendFirebaseMessage([], mockNotification); | ||
|
||
expect(logger.warning).toHaveBeenCalledWith(expect.objectContaining({ | ||
message: 'Attempted to send Firebase message to user with no registration tokens', | ||
notificationType: mockNotification.type, | ||
})); | ||
}); | ||
|
||
it('should log an error if sending the message fails', async () => { | ||
const mockedSendMulticast = sendMulticast as jest.MockedFunction<typeof sendMulticast>; | ||
mockedSendMulticast.mockRejectedValueOnce(new Error('Send failed')); | ||
|
||
await sendFirebaseMessage([defaultToken.token], mockNotification); | ||
|
||
expect(logger.error).toHaveBeenCalledWith(expect.objectContaining({ | ||
message: 'Failed to send Firebase message', | ||
notificationType: mockNotification.type, | ||
})); | ||
}); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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