-
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.
- Loading branch information
Showing
21 changed files
with
293 additions
and
143 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules/ | |
/playwright-report/ | ||
/playwright/.cache/ | ||
.env | ||
/dist |
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,9 @@ | ||
{ | ||
"email": "[email protected]", | ||
"address": "p", | ||
"country_id": "ID", | ||
"phone_number": "08873376261", | ||
"phone_code": "62", | ||
"last_name": "wahyu", | ||
"first_name": "wahyu" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import path from "path"; | ||
import fs from "fs/promises"; | ||
|
||
class FileHandler { | ||
async getFile( | ||
file_type: string, | ||
file_status: any, | ||
file_extension: any, | ||
mime_type: any, | ||
is64: boolean | ||
): Promise<{ name: string; mimeType: string; buffer: Buffer }> { | ||
const filePath = path.resolve( | ||
"data/etc", | ||
`${file_type}_example`, | ||
`${file_status}_${mime_type}_${file_type}.${file_extension}` | ||
); | ||
|
||
const file: any = await fs.readFile(filePath); | ||
|
||
if (is64) { | ||
return file.toString("base64"); | ||
} | ||
|
||
return { | ||
name: filePath, | ||
mimeType: file_type === "image" ? `image/${mime_type}` : `application/${mime_type}`, | ||
buffer: file, | ||
}; | ||
} | ||
} | ||
|
||
export default FileHandler; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import fetch from "node-fetch"; | ||
import dotenv from "dotenv"; | ||
|
||
class Authenticate { | ||
async getBearer(type: any): Promise<string> { | ||
dotenv.config(); | ||
|
||
const beforeAsyncResponse = await fetch(process.env.API_LOGIN_URL!, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Accept": "*/*", | ||
}, | ||
body: JSON.stringify(this.checkType(type)) | ||
|
||
}); | ||
|
||
const beforeAsyncResponseJson: Record<string, any> = (await beforeAsyncResponse.json()); | ||
const bearer: string = beforeAsyncResponseJson.data.access_token; | ||
|
||
return bearer; | ||
} | ||
|
||
checkType(type: string): Record<string, any> { | ||
let body: Record<string, any>; | ||
|
||
if (type === "username") { | ||
body = { | ||
username: process.env.USERNAME, | ||
password: process.env.PASSWORD, | ||
}; | ||
} else { | ||
body = { | ||
email: process.env.EMAIL, | ||
password: process.env.PASSWORD, | ||
}; | ||
} | ||
|
||
return body; | ||
} | ||
} | ||
|
||
export default Authenticate |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import Authenticate from "./generate_bearer"; | ||
|
||
class HeaderHandler { | ||
async getHeader( | ||
type: any, | ||
multipart: boolean = false | ||
): Promise<Record<string, any>> { | ||
const auth: Authenticate = new Authenticate() | ||
const bearerToken = await auth.getBearer(type) | ||
|
||
let headers: Record<string, any> = { | ||
"accept": "*/*", | ||
"Authorization": "Bearer " + bearerToken | ||
}; | ||
|
||
if (multipart === false) { | ||
headers["Content-Type"] = "application/json"; | ||
} else { | ||
headers["Content-Type"] = "application/x-www-form-urlencoded"; | ||
} | ||
|
||
return headers; | ||
} | ||
} | ||
|
||
export default HeaderHandler |
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 |
---|---|---|
@@ -1,23 +1,26 @@ | ||
import fetch from "node-fetch"; | ||
|
||
class Randomizer { | ||
private wordApiUrl: string; | ||
|
||
constructor() { | ||
this.wordApiUrl = "https://random-word-api.herokuapp.com/word?number=1"; | ||
} | ||
|
||
async randomWord() { | ||
async randomWord(): Promise<string> { | ||
try { | ||
const response = await fetch(this.wordApiUrl); | ||
const words = await response.json(); | ||
const words: string[] = await response.json(); | ||
return words[0].toUpperCase(); | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} | ||
|
||
async randomNumber(min, max) { | ||
async randomNumber(min: number, max: number): Promise<number> { | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
} | ||
} | ||
|
||
export default Randomizer | ||
export default Randomizer; |
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
Oops, something went wrong.