Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store in progress state directly after signup #34

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
store in progress state directly after signup
in order to make account accessible in case there occured an error
during creation.

And push dynamodb code into module.
  • Loading branch information
schnipseljagd committed Jan 18, 2023
commit c316fe2a3a322e9a6dfad7795997d68be1056444
55 changes: 10 additions & 45 deletions code/create-account/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const util = require("util");
const puppeteer = require("puppeteer");
const {getDocument, queries} = require('pptr-testing-library')
const passwordGenerator = require("generate-password");
const db = require("./lib/db")

const CONNECT_SSM_PARAMETER = "/superwerker/tests/connect"; // TODO: rename
const PRINCIPAL = process.env["PRINCIPAL"];
Expand Down Expand Up @@ -121,6 +122,13 @@ const signup = async function () {
console.log("signupVerification");
await signupVerification(page, variables, ACCOUNT_NAME, ssm);

console.log("saveAccountAndSetToInProgress")
await db.saveAccountAndSetToInProgress(
ACCOUNT_NAME,
ACCOUNT_EMAIL,
password
);

console.log("loginToAccount");
await loginToAccount(
page,
Expand All @@ -141,13 +149,8 @@ const signup = async function () {
console.log("checkIfAccountIsReady");
await checkIfAccountIsReady(accountId);

console.log("saveAccountIdAndFinish");
await saveAccountIdAndFinish(
ACCOUNT_NAME,
ACCOUNT_EMAIL,
accountId,
password
);
console.log("saveAccountAndSetToCreated");
await db.saveAccountAndSetToCreated(ACCOUNT_NAME, accountId);

await browser.close();
};
Expand Down Expand Up @@ -486,44 +489,6 @@ async function getAccountId(page) {
return account["accountId"];
}

async function saveAccountIdAndFinish(
ACCOUNT_NAME,
ACCOUNT_EMAIL,
accountId,
password
) {
const ddb = new AWS.DynamoDB();
await ddb
.updateItem({
Key: {
account_name: {
S: ACCOUNT_NAME,
},
},
TableName: "account",
UpdateExpression:
"SET account_id = :account_id, account_email = :account_email, registration_date = :registration_date, account_status = :account_status, password = :password",
ExpressionAttributeValues: {
":account_id": {
S: accountId,
},
":account_email": {
S: ACCOUNT_EMAIL,
},
":registration_date": {
S: new Date().toISOString(),
},
":account_status": {
S: "CREATED",
},
":password": {
S: password,
},
},
})
.promise();
}

async function solveCaptcheHandler(
page,
account_name,
Expand Down
65 changes: 65 additions & 0 deletions code/create-account/lib/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const AWS = require("aws-sdk");

const saveAccountAndSetToInProgress = async (
ACCOUNT_NAME,
ACCOUNT_EMAIL,
password
) => {
const ddb = new AWS.DynamoDB();
await ddb
.updateItem({
Key: {
account_name: {
S: ACCOUNT_NAME,
},
},
TableName: "account",
UpdateExpression:
"SET account_email = :account_email, registration_date = :registration_date, account_status = :account_status, password = :password",
ExpressionAttributeValues: {
":account_email": {
S: ACCOUNT_EMAIL,
},
":registration_date": {
S: new Date().toISOString(),
},
":account_status": {
S: "IN_PROGRESS",
},
":password": {
S: password,
},
},
})
.promise();
}


const saveAccountAndSetToCreated = async (
ACCOUNT_NAME,
accountId
) => {
const ddb = new AWS.DynamoDB();
await ddb
.updateItem({
Key: {
account_name: {
S: ACCOUNT_NAME,
},
},
TableName: "account",
UpdateExpression:
"SET account_id = :account_id, account_status = :account_status",
ExpressionAttributeValues: {
":account_id": {
S: accountId,
},
":account_status": {
S: "CREATED",
}
},
})
.promise();
}

module.exports = { saveAccountAndSetToInProgress, saveAccountAndSetToCreated }