powerful-orange-86819
08/24/2022, 7:28 AMhandsome-lion-1748
08/26/2022, 8:40 AMpowerful-orange-86819
08/26/2022, 11:41 AMjs
on("task", {
DATABASE({ config, dbName, port, sql, values }) {
config.database = dbName;
config.port = port;
const pool = new pg.Pool(config);
try {
return pool.query(sql, values);
} catch (e) {}
},
});
Then simply call the task in a custom command or directly in tests (second one I find very anti-pattern, personally prefer code and tests to be completely separate)
js
cy.task("DATABASE", {
config: postgres, // add to env
dbName: "clients", //write on each separate
port: 9999, //add to env
sql: `select player from clients
where player_name = '${username}'`, //directly copy paste sql query
}).then((result) => {
results = result.rows[0].username; // get the results by using results.rows[0]
});powerful-orange-86819
08/26/2022, 11:41 AM