-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Building workaround to test payments flow...
- Loading branch information
Showing
10 changed files
with
132 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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import axios from "axios"; | ||
import querystring from "querystring"; | ||
import request from "supertest"; | ||
|
||
export const purchaseCourseForUserByAdmin = async (userEmail: string) => { | ||
const accessToken = await getAccessTokenForAdmin(); | ||
|
||
const result = await axios.post( | ||
`http://localhost:9000/admin/course-pay`, | ||
{ | ||
userEmail, | ||
courseId: "fpvPtfu7s", | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}, | ||
); | ||
|
||
return "OK"; | ||
}; | ||
|
||
const getAccessTokenFromRedirect = (redirect: string) => { | ||
const indexOfQuestionMark = redirect.indexOf("?"); | ||
const queryParams = redirect.slice(indexOfQuestionMark + 1); | ||
const params = querystring.parse(queryParams); | ||
return params.accessToken; | ||
}; | ||
|
||
const getAccessTokenForAdmin = async (): Promise<string> => { | ||
let authorizationRedirect; | ||
let loginRedirect; | ||
let accessToken; | ||
|
||
await request(`http://localhost:9000/auth/google`) | ||
.get("/") | ||
.expect(302) | ||
.then(response => { | ||
authorizationRedirect = response.header.location; | ||
}); | ||
|
||
await request(authorizationRedirect) | ||
.get("/") | ||
.expect(302) | ||
.then(response => { | ||
loginRedirect = response.header.location; | ||
}); | ||
|
||
await request(loginRedirect) | ||
.get("/") | ||
.expect(302) | ||
.then(response => { | ||
accessToken = getAccessTokenFromRedirect(response.header.location); | ||
}); | ||
|
||
return accessToken; | ||
}; |
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