-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(apple): emit notification when apple user migration is complete
- Loading branch information
Showing
9 changed files
with
166 additions
and
5 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
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 |
---|---|---|
|
@@ -171,7 +171,7 @@ describe('ApplePocketFxAMigration', function() { | |
}); | ||
|
||
describe('AppleUser', function() { | ||
let sandbox, dbStub, user, writeStreamStub; | ||
let sandbox, dbStub, user, writeStreamStub, log; | ||
beforeEach(function() { | ||
sandbox = sinon.createSandbox(); | ||
dbStub = { | ||
|
@@ -184,7 +184,10 @@ describe('AppleUser', function() { | |
writeStreamStub = { | ||
write: sandbox.stub() | ||
}; | ||
user = new AppleUser('[email protected]', 'transferSub', 'uid', ['[email protected]'], dbStub, writeStreamStub, config); | ||
log = { | ||
notifyAttachedServices: sandbox.stub().resolves() | ||
} | ||
user = new AppleUser('[email protected]', 'transferSub', 'uid', ['[email protected]'], dbStub, writeStreamStub, config, false, log); | ||
}); | ||
|
||
afterEach(function() { | ||
|
@@ -300,5 +303,15 @@ describe('AppleUser', function() { | |
user.saveResult(); | ||
const expectedOutput = 'transferSub,uid,[email protected],[email protected],true,\n'; | ||
assert.calledWith(user.writeStream.write, expectedOutput); | ||
|
||
assert.calledOnceWithExactly(user.log.notifyAttachedServices, 'appleUserMigration', {}, | ||
{ | ||
uid: 'uid', | ||
appleEmail:'[email protected]', | ||
fxaEmail:'[email protected]', | ||
transferSub: 'transferSub', | ||
success: true, | ||
err: '', | ||
}) | ||
}); | ||
}); |
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
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 |
---|---|---|
|
@@ -70,6 +70,18 @@ const baseProfileMessage = { | |
event: 'profileDataChange', | ||
}; | ||
|
||
const appleMigrationMessage = { | ||
event: 'appleUserMigration', | ||
timestamp: now, | ||
ts: now / 1000, | ||
uid: '993d26bac72b471991b197b3d298a5de', | ||
fxaEmail: '[email protected]', | ||
appleEmail: '[email protected]', | ||
transferSub: '123', | ||
success: true, | ||
err: '', | ||
}; | ||
|
||
const updateStubMessage = (message: any) => { | ||
return { | ||
Body: JSON.stringify(message), | ||
|
@@ -149,6 +161,7 @@ describe('QueueworkerService', () => { | |
serviceNotificationQueueUrl: | ||
'https://sqs.us-east-2.amazonaws.com/queue.mozilla/321321321/notifications', | ||
log: { app: 'test' }, | ||
topicPrefix: 'rp', | ||
}; | ||
const MockConfig: Provider = { | ||
provide: ConfigService, | ||
|
@@ -250,6 +263,28 @@ describe('QueueworkerService', () => { | |
'resource-server-client-id', | ||
]); | ||
}); | ||
|
||
it('handles apple migration event', async () => { | ||
const msg = updateStubMessage(appleMigrationMessage); | ||
await (service as any).handleMessage(msg); | ||
|
||
const topicName = 'rp749818d3f2e7857f'; | ||
expect(pubsub.topic).toBeCalledWith(topicName); | ||
expect(pubsub.topic(topicName).publishMessage).toBeCalledTimes(1); | ||
expect(pubsub.topic(topicName).publishMessage).toBeCalledWith({ | ||
json: { | ||
'appleEmail': '[email protected]', | ||
'err': '', | ||
'event': 'appleUserMigration', | ||
'fxaEmail': '[email protected]', | ||
'success': true, | ||
'timestamp': now, | ||
'transferSub': '123', | ||
'ts': now / 1000, | ||
'uid': '993d26bac72b471991b197b3d298a5de', | ||
}, | ||
}); | ||
}); | ||
|
||
const fetchOnValidMessage = { | ||
'delete message': baseDeleteMessage, | ||
|
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