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

chore: update RWA to make running locally easier #1524

Merged
merged 8 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
5 changes: 4 additions & 1 deletion backend/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const schemaWithResolvers = addResolversToSchema({
const app = express();

/* istanbul ignore next */
// @ts-ignore
// @ts-expect-error
if (global.__coverage__) {
require("@cypress/code-coverage/middleware/express")(app);
}
Expand All @@ -55,16 +55,19 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.use(
// @ts-expect-error
session({
secret: "session secret",
resave: false,
saveUninitialized: false,
unset: "destroy",
})
);
// @ts-expect-error
app.use(passport.initialize());
app.use(passport.session());

// @ts-expect-error
app.use(paginate.middleware(+process.env.PAGINATION_PAGE_SIZE!));

/* istanbul ignore next */
Expand Down
2 changes: 1 addition & 1 deletion backend/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ router.post("/login", passport.authenticate("local"), (req: Request, res: Respon

router.post("/logout", (req: Request, res: Response): void => {
res.clearCookie("connect.sid");
req.logout();
req.logout(() => res.redirect("/"));
req.session!.destroy(function (err) {
res.redirect("/");
});
Expand Down
14 changes: 7 additions & 7 deletions backend/transaction-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ router.get(
const transactions = getTransactionsForUserForApi(req.user?.id!, req.query);

const { totalPages, data: paginatedItems } = getPaginatedItems(
req.query.page,
req.query.limit,
req.query.page as unknown as number,
req.query.limit as unknown as number,
transactions
);

Expand Down Expand Up @@ -72,8 +72,8 @@ router.get(
const transactions = getTransactionsForUserContacts(req.user?.id!, req.query);

const { totalPages, data: paginatedItems } = getPaginatedItems(
req.query.page,
req.query.limit,
req.query.page as unknown as number,
req.query.limit as unknown as number,
transactions
);

Expand All @@ -96,7 +96,7 @@ router.get(
ensureAuthenticated,
validateMiddleware(isTransactionPublicQSValidator),
(req, res) => {
const isFirstPage = req.query.page === 1;
const isFirstPage = (req.query.page as unknown as number) === 1;

/* istanbul ignore next */
let transactions = !isEmpty(req.query)
Expand All @@ -115,8 +115,8 @@ router.get(
}

const { totalPages, data: paginatedItems } = getPaginatedItems(
req.query.page,
req.query.limit,
req.query.page as unknown as number,
req.query.limit as unknown as number,
isFirstPage ? publicTransactionsWithContacts : publicTransactions
);

Expand Down
2 changes: 1 addition & 1 deletion backend/user-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ router.get("/search", ensureAuthenticated, validateMiddleware([searchValidation]
const { q } = req.query;

/* istanbul ignore next */
const users = removeUserFromResults(req.user?.id!, searchUsers(q));
const users = removeUserFromResults(req.user?.id!, searchUsers(q as string));

res.status(200).json({ results: users });
});
Expand Down
35 changes: 31 additions & 4 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ import axios from "axios";
import dotenv from "dotenv";
import Promise from "bluebird";
import codeCoverageTask from "@cypress/code-coverage/task";
import { devServer } from "@cypress/vite-dev-server";
import { defineConfig } from "cypress";
import { mergeConfig, loadEnv } from "vite";

dotenv.config({ path: ".env.local" });
dotenv.config();

const awsConfig = require(path.join(__dirname, "./aws-exports-es5.js"));
let awsConfig = {
default: undefined,
};

try {
awsConfig = require(path.join(__dirname, "./aws-exports-es5.js"));
} catch (e) {}

module.exports = defineConfig({
projectId: "7s5okt",
Expand Down Expand Up @@ -52,9 +60,28 @@ module.exports = defineConfig({
googleClientSecret: process.env.VITE_GOOGLE_CLIENT_SECRET,
},
component: {
devServer: {
framework: "react",
bundler: "vite",
devServer(devServerConfig) {
const viteConfig = require("./vite.config.ts");
const conf = {
define: {
"process.env": loadEnv("development", process.cwd(), "VITE"),
},
server: {
/**
* start the CT dev server on a different port than the full RWA
* so users can switch between CT and E2E testing without having to
* stop/start the RWA dev server.
*/
port: 3002,
},
};

const resolvedViteConfig = mergeConfig(viteConfig, conf);
return devServer({
...devServerConfig,
framework: "react",
viteConfig: resolvedViteConfig,
});
},
specPattern: "src/**/*.cy.{js,jsx,ts,tsx}",
supportFile: "cypress/support/component.ts",
Expand Down
1 change: 1 addition & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Cypress.Commands.add("reactComponent", { prevSubject: "element" }, ($el) => {
});

Cypress.Commands.add("setTransactionAmountRange", (min, max) => {
// eslint-disable-next-line cypress/unsafe-to-chain-command
AtofStryker marked this conversation as resolved.
Show resolved Hide resolved
cy.getBySel("transaction-list-filter-amount-range-button")
.scrollIntoView()
.click({ force: true });
Expand Down
2 changes: 1 addition & 1 deletion cypress/tests/ui/transaction-view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("Transaction View", function () {
cy.wait("@getTransaction");

cy.getBySelLike("like-button").click();
cy.getBySelLike("like-count").should("contain", 1);
cy.getBySelLike("like-count").should("contain", 2);
cy.getBySelLike("like-button").should("be.disabled");
cy.visualSnapshot("Transaction after Liked");
});
Expand Down
Loading