-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(notifications): Add notification services e2e mocks (#25065)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This adds mocks for the notification services when running e2e tests. This also unblocks the notifications team from starting e2e tests for our flows. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25065?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information
1 parent
b1eeaf7
commit 8a08568
Showing
23 changed files
with
546 additions
and
227 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
60 changes: 60 additions & 0 deletions
60
app/scripts/controllers/authentication/mocks/mockResponses.ts
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,60 @@ | ||
import { | ||
AUTH_LOGIN_ENDPOINT, | ||
AUTH_NONCE_ENDPOINT, | ||
LoginResponse, | ||
NonceResponse, | ||
OAuthTokenResponse, | ||
OIDC_TOKENS_ENDPOINT, | ||
} from '../services'; | ||
|
||
type MockResponse = { | ||
url: string; | ||
requestMethod: 'GET' | 'POST' | 'PUT'; | ||
response: unknown; | ||
}; | ||
|
||
export const MOCK_NONCE = '4cbfqzoQpcNxVImGv'; | ||
export const MOCK_NONCE_RESPONSE: NonceResponse = { | ||
nonce: MOCK_NONCE, | ||
}; | ||
|
||
export function getMockAuthNonceResponse() { | ||
return { | ||
url: AUTH_NONCE_ENDPOINT, | ||
requestMethod: 'GET', | ||
response: MOCK_NONCE_RESPONSE, | ||
} satisfies MockResponse; | ||
} | ||
|
||
export const MOCK_JWT = | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'; | ||
export const MOCK_LOGIN_RESPONSE: LoginResponse = { | ||
token: MOCK_JWT, | ||
expires_in: new Date().toString(), | ||
profile: { | ||
identifier_id: 'MOCK_IDENTIFIER', | ||
profile_id: 'MOCK_PROFILE_ID', | ||
}, | ||
}; | ||
|
||
export function getMockAuthLoginResponse() { | ||
return { | ||
url: AUTH_LOGIN_ENDPOINT, | ||
requestMethod: 'POST', | ||
response: MOCK_LOGIN_RESPONSE, | ||
} satisfies MockResponse; | ||
} | ||
|
||
export const MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${MOCK_JWT}`; | ||
export const MOCK_OATH_TOKEN_RESPONSE: OAuthTokenResponse = { | ||
access_token: MOCK_ACCESS_TOKEN, | ||
expires_in: new Date().getTime(), | ||
}; | ||
|
||
export function getMockAuthAccessTokenResponse() { | ||
return { | ||
url: OIDC_TOKENS_ENDPOINT, | ||
requestMethod: 'POST', | ||
response: MOCK_OATH_TOKEN_RESPONSE, | ||
} satisfies MockResponse; | ||
} |
45 changes: 13 additions & 32 deletions
45
app/scripts/controllers/authentication/mocks/mockServices.ts
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
23 changes: 1 addition & 22 deletions
23
app/scripts/controllers/metamask-notifications/mocks/mock-feature-announcements.ts
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
58 changes: 0 additions & 58 deletions
58
app/scripts/controllers/metamask-notifications/mocks/mock-onchain-notifications.ts
This file was deleted.
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
59 changes: 59 additions & 0 deletions
59
app/scripts/controllers/metamask-notifications/mocks/mockResponses.ts
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,59 @@ | ||
import { FEATURE_ANNOUNCEMENT_API } from '../services/feature-announcements'; | ||
import { | ||
NOTIFICATION_API_LIST_ENDPOINT, | ||
NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT, | ||
TRIGGER_API_BATCH_ENDPOINT, | ||
} from '../services/onchain-notifications'; | ||
import { createMockFeatureAnnouncementAPIResult } from './mock-feature-announcements'; | ||
import { createMockRawOnChainNotifications } from './mock-raw-notifications'; | ||
|
||
type MockResponse = { | ||
url: string; | ||
requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE'; | ||
response: unknown; | ||
}; | ||
|
||
export const CONTENTFUL_RESPONSE = createMockFeatureAnnouncementAPIResult(); | ||
|
||
export function getMockFeatureAnnouncementResponse() { | ||
return { | ||
url: FEATURE_ANNOUNCEMENT_API, | ||
requestMethod: 'GET', | ||
response: CONTENTFUL_RESPONSE, | ||
} satisfies MockResponse; | ||
} | ||
|
||
export function getMockBatchCreateTriggersResponse() { | ||
return { | ||
url: TRIGGER_API_BATCH_ENDPOINT, | ||
requestMethod: 'POST', | ||
response: null, | ||
} satisfies MockResponse; | ||
} | ||
|
||
export function getMockBatchDeleteTriggersResponse() { | ||
return { | ||
url: TRIGGER_API_BATCH_ENDPOINT, | ||
requestMethod: 'DELETE', | ||
response: null, | ||
} satisfies MockResponse; | ||
} | ||
|
||
export const MOCK_RAW_ON_CHAIN_NOTIFICATIONS = | ||
createMockRawOnChainNotifications(); | ||
|
||
export function getMockListNotificationsResponse() { | ||
return { | ||
url: NOTIFICATION_API_LIST_ENDPOINT, | ||
requestMethod: 'POST', | ||
response: MOCK_RAW_ON_CHAIN_NOTIFICATIONS, | ||
} satisfies MockResponse; | ||
} | ||
|
||
export function getMockMarkNotificationsAsReadResponse() { | ||
return { | ||
url: NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT, | ||
requestMethod: 'POST', | ||
response: null, | ||
} satisfies MockResponse; | ||
} |
Oops, something went wrong.