Skip to content

Instantly share code, notes, and snippets.

@agusrichard
Last active October 23, 2021 18:17
Show Gist options
  • Save agusrichard/aaea6e4631a9956bca3216f1f03ebb31 to your computer and use it in GitHub Desktop.
Save agusrichard/aaea6e4631a9956bca3216f1f03ebb31 to your computer and use it in GitHub Desktop.
export function setup() {
const authParams = {
headers: { 'Content-Type': 'application/json' },
}
const authPayload = {
email: '[email protected]',
password: 'user1',
fullname: 'user1'
}
http.post(`${BASE_URL}/users/register`, JSON.stringify(authPayload), authParams)
const loginResponse = http.post(`${BASE_URL}/users/login`, JSON.stringify(authPayload), authParams)
// Catch the login response to get id, token and email
const result = loginResponse.json().data
// This params will be used to create income/expense types
const params = {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${result.token}`
}
}
// Just two kinds of income and expense
const types = ['Investment', 'Taxes']
types.forEach(t => {
// Create income/expense type, e.g Investment, Pay taxes, Shopping, etc.
http.post(
`${BASE_URL}/income-expense-type/create`,
JSON.stringify({
description: t
}),
params
)
})
// We get the newly created income/expense types
// To be used to test create incomes and expenses
const response = http.get(`${BASE_URL}/income-expense-type/find-by-user`, params)
// The returned values will be used later inside the default
// and teardown function
return {
id: result.id,
email: result.email,
token: result.token,
incomeExpenseTypes: response.json().data
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment