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

Mntor-3289-1: tests reverted in mntor-3289 #4742

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
bccbb1e
feat: mock HIBP
mansaj May 29, 2024
b32ca9f
Merge branch 'MNTOR-3227-2' of https://github.com/mozilla/blurts-serv…
Jun 11, 2024
a0d9df7
able to default to mock endpoint on failure locally.
Jun 13, 2024
695e1fc
made it host-flexibile for HIBP fallback
Jun 13, 2024
e07af0e
npx prettified fakeBraches.json
Jun 13, 2024
c0b253a
made the code cleaner, and switch back to true endpoint after using f…
Jun 13, 2024
25b590b
got rid of second promise wait
Jun 13, 2024
ffb0550
Merge branch 'main' of https://github.com/mozilla/blurts-server into …
Jun 17, 2024
ab680af
removed other features, kept only the mock endpoint
Jun 17, 2024
184cfcf
made breaches list match the fake breaches for a user
Jun 17, 2024
b7d9575
Merge branch 'main' of https://github.com/mozilla/blurts-server into …
Jun 17, 2024
c922556
Merge branch 'main' of https://github.com/mozilla/blurts-server into …
Jun 18, 2024
dda9c22
file endpoint additions
Jun 20, 2024
d809bea
Merge branch 'main' of https://github.com/mozilla/blurts-server into …
Jun 24, 2024
0f1d778
Merge branch 'main' of https://github.com/mozilla/blurts-server into …
Jun 25, 2024
988997c
funtional commit - mocked accessed endpoints
Jun 25, 2024
fb2d028
fixed the path overwriting issue, added responsive dynamic configurat…
Jun 25, 2024
2a4e504
moved mock user data into a separate file
Jun 26, 2024
0b1d9e5
fixed some code quality and substitued constants with function calls
Jun 26, 2024
f94238e
Merge branch 'main' of https://github.com/mozilla/blurts-server into …
Jun 26, 2024
29b6f0e
Allowed for data to be configured dynamically using an endpoint
Jun 26, 2024
8ec080d
lint fail fixed
Jun 26, 2024
9140e01
Merge branch 'main' of https://github.com/mozilla/blurts-server into …
Jun 26, 2024
f3e9b37
most tests pass when using mock onerep endpoint
Jun 26, 2024
bc7c4de
Merge branch 'main' of https://github.com/mozilla/blurts-server into …
Jun 28, 2024
11cb314
Merge branch 'main' of https://github.com/mozilla/blurts-server into …
Jun 28, 2024
71e5ddf
passes all tests except for those in purchase spec
Jun 28, 2024
d6eb4ed
added production checks
Jun 28, 2024
842b229
fixed lint errors
Jun 29, 2024
9d368c0
reverting smoke test
Jun 29, 2024
29af535
cleaned up query params and dynamic routing
Jun 29, 2024
fa16c41
fixed lint errors and corrected a POST endpoint
Jun 29, 2024
f3378b0
added form input
Jun 30, 2024
0a4e15b
substituted direct magic numbers access to wrapper methods
Jun 30, 2024
f076a56
merging with 3285
Jun 30, 2024
06b25ca
mock endpoint config - basic version
Jun 30, 2024
cf0ebf6
added more type checks and proper defaults
Jun 30, 2024
9fed164
functional OneRep config page, with styling
Jun 30, 2024
c98d0b2
lint error
Jun 30, 2024
f8e6b52
added a configuration endpoint and page for HIBP
Jul 1, 2024
a249654
reset package-lock
Jul 1, 2024
cb8e013
lint
Jul 1, 2024
21a6bc5
package-lock
Jul 1, 2024
839a9da
slightly modified hibp/breaches
Jul 1, 2024
feaf567
removed database retrieval from mock hibp endpoint
Jul 1, 2024
d3219fb
Merge branch 'main' of https://github.com/mozilla/blurts-server into …
Jul 1, 2024
f693e1a
Merged with main + minor error log change
Jul 1, 2024
9401fed
reverted e2e changes
Jul 2, 2024
d581682
e2e check
Jul 2, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
funtional commit - mocked accessed endpoints
  • Loading branch information
Mukhamediyar Kudaikulov committed Jun 25, 2024
commit 988997c80d8069af2a400ba781e4bc7341187861
10 changes: 10 additions & 0 deletions src/app/api/mock/onerep/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { StateAbbr } from "../../../../../utils/states";

export const MOCK_PROFILE_ID = 777;
export const MOCK_SCAN_ID = 6972;
export const MOCK_TIME = "2024-06-19T01:37:02+0000";
export const MOCK_FIRSTNAME = "John";
export const MOCK_LASTNAME = "Doe";
export const MOCK_BIRTHDATE = "2000-01-01";

export const MOCK_ADDRESSES: [{ city: string; state: StateAbbr }] = [
{ city: "Berkeley", state: "CA" as StateAbbr },
];
39 changes: 39 additions & 0 deletions src/app/api/mock/onerep/config/userObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

export type RequestProfileData = {
first_name: string;
last_name: string;
middle_name: string;
birth_date: string;
addresses: Array<{ state: string; city: string }>;
};

export type ResponseProfileData = {
id: number;
first_name: string;
last_name: string;
middle_name: string | null;
birth_date: string;
first_names: string[];
middle_names: string[];
last_names: string[];
phone_numbers: string[];
emails: string[];
addresses: Array<{
id: number;
profile_id: number;
state: string;
city: string;
address_line: string | null;
zip: string | null;
created_at: string;
updated_at: string;
url: string;
}>;
status: "active" | "inactive";
created_at: string;
updated_at: string;
url: string;
};
6 changes: 6 additions & 0 deletions src/app/api/mock/onerep/data-brokers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { NextResponse } from "next/server";

//ONLY PART OF ADMIN - probably shouldn't mock?
export default function handler() {
return NextResponse.json({ error: "You've reached a mock endpoint" });
}
15 changes: 15 additions & 0 deletions src/app/api/mock/onerep/profiles/[profileId]/activate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { NextRequest, NextResponse } from "next/server";

export function PUT(req: NextRequest) {
const profileId: number = Number(req.url.match(/profiles\/([0-9]+)/)![1]);

if (!profileId || isNaN(profileId)) {
return NextResponse.json({ error: "Invalid profile ID" });
}

//TODO: update the json file corresponding to this user

return NextResponse.json({
message: `Profile ${profileId} successfully activated`,
});
}
15 changes: 15 additions & 0 deletions src/app/api/mock/onerep/profiles/[profileId]/deactivate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { NextRequest, NextResponse } from "next/server";

export function PUT(req: NextRequest) {
const profileId: number = Number(req.url.match(/profiles\/([0-9]+)/)![1]);

if (!profileId || isNaN(profileId)) {
return NextResponse.json({ error: "Invalid profile ID" });
}

//TODO: update the json file corresponding to this user

return NextResponse.json({
message: `Profile ${profileId} successfully deactivated`,
});
}
15 changes: 15 additions & 0 deletions src/app/api/mock/onerep/profiles/[profileId]/optout/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { NextRequest, NextResponse } from "next/server";

export function PUT(req: NextRequest) {
const profileId: number = Number(req.url.match(/profiles\/([0-9]+)/)![1]);

if (!profileId || isNaN(profileId)) {
return NextResponse.json({ error: "Invalid profile ID" });
}

//TODO: update the json file corresponding to this user

return NextResponse.json({
message: `Profile ${profileId} successfully opted out`,
});
}
52 changes: 33 additions & 19 deletions src/app/api/mock/onerep/profiles/[profileId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,46 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { NextApiRequest, NextApiResponse } from "next";
import { ShowProfileResponse } from "../../../../../functions/server/onerep";
import {
MOCK_TIME,
MOCK_FIRSTNAME,
MOCK_LASTNAME,
MOCK_BIRTHDATE,
MOCK_ADDRESSES,
} from "../../config/config.ts";
import { ShowProfileResponse } from "../../../../../functions/server/onerep.ts";
import { NextRequest, NextResponse } from "next/server";

// Mocked profile data to simulate response
const mockProfileData: ShowProfileResponse = {
id: 0,
first_name: "",
last_name: "",
birth_date: "",
addresses: [{ state: "", city: "" }],
status: "",
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
url: `https://api.onerep.com/profiles/`,
};
//TODO: mock out the URL

async function extractProfileId(req: NextRequest) {
const idFromBody: number = req.body !== null && (await req.json()).profileId;
if (idFromBody) return idFromBody;
const idFromUrl: number = Number(req.url.match(/profiles\/([0-9]+)/)![1]);
return idFromUrl;
}

// Mock endpoint to simulate fetching a profile by ID
export default function GET(req: NextApiRequest, res: NextApiResponse) {
export async function GET(req: NextRequest) {
// Extract profileId from query parameters or request body
const profileId: number = Number(req.query.profileId || req.body.profileId);
const profileId: number = await extractProfileId(req);

// Simulate error if profileId is not provided or not valid
if (!profileId || isNaN(profileId)) {
res.status(400).json({ error: "Invalid profile ID" });
return;
return NextResponse.json({ error: "Invalid profile ID" }, { status: 400 });
}

res.status(200).json(mockProfileData);
const mockProfileData: ShowProfileResponse = {
id: profileId,
first_name: MOCK_FIRSTNAME,
last_name: MOCK_LASTNAME,
birth_date: MOCK_BIRTHDATE,
addresses: MOCK_ADDRESSES,
status: "inactive",
created_at: MOCK_TIME,
updated_at: MOCK_TIME,
url: `${process.env.ONEREP_API_BASE}/profiles/${profileId}`,
};

return NextResponse.json(mockProfileData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,24 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// pages/api/profiles/[profileId]/scans/[scanId].ts

import { MOCK_TIME } from "../../../../config/config";
import { NextRequest, NextResponse } from "next/server";

export function GET(req: NextRequest) {
const profileId = Number(req.url.match(/profiles\/([0-9]+)/)![1]);
const scanId = Number(req.url.match(/scans\/([0-9]+)/)![1]);

// Check for the availability of the scan
const responseData = {
id: scanId,
profile_id: profileId,
status: "finished",
reason: "manual",
created_at: MOCK_TIME,
updated_at: MOCK_TIME,
url: `${process.env.ONEREP_API_BASE}/profiles/${profileId}/scans/${scanId}`,
};
return NextResponse.json(responseData);
}
67 changes: 67 additions & 0 deletions src/app/api/mock/onerep/profiles/[profileId]/scans/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,70 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { MOCK_SCAN_ID, MOCK_TIME } from "../../../config/config";
import { NextRequest, NextResponse } from "next/server";

//TODO: mock out the id field and url

function extractProfileId(req: NextRequest) {
const idFromUrl = Number(req.url.match(/profiles\/([0-9]+)\/scans/)![1]);
return idFromUrl;
}

export function POST(req: NextRequest) {
const profileId: number = extractProfileId(req);
if (!profileId || isNaN(profileId)) {
return NextResponse.json({ error: "Invalid profile ID" });
}

const mockResponse = {
id: MOCK_SCAN_ID,
profile_id: profileId,
status: "finished",
reason: "manual",
created_at: MOCK_TIME,
updated_at: MOCK_TIME,
url: `${process.env.ONEREP_API_BASE}/profiles/${profileId}/scans/${MOCK_SCAN_ID}`,
};

return NextResponse.json(mockResponse);
}

export function GET(req: NextRequest) {
const profileId: number = extractProfileId(req);

if (!profileId || isNaN(profileId)) {
return NextResponse.json({ error: "Invalid profile ID" });
}

//TODO: mock out ID here and urls
const responseData = {
data: [
{
id: MOCK_SCAN_ID,
profile_id: profileId,
status: "finished",
reason: "manual",
created_at: MOCK_TIME,
updated_at: MOCK_TIME,
url: `${process.env.ONEREP_API_BASE}/profiles/${profileId}/scans/${MOCK_SCAN_ID}`,
},
],
links: {
first: `${process.env.ONEREP_API_BASE}/profiles/${profileId}/scans?page=1`,
last: `${process.env.ONEREP_API_BASE}/profiles/${profileId}/scans?page=1`,
prev: null,
next: null,
},
meta: {
current_page: 1,
from: 1,
last_page: 1,
path: `${process.env.ONEREP_API_BASE}/profiles/${profileId}/scans`,
per_page: 20,
to: 1,
total: 1,
},
};
return NextResponse.json(responseData);
}
76 changes: 24 additions & 52 deletions src/app/api/mock/onerep/profiles/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,26 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import type { NextApiRequest, NextApiResponse } from "next";
import { MOCK_PROFILE_ID, MOCK_TIME } from "../config/config.ts";

type RequestProfileData = {
first_name: string;
last_name: string;
middle_name: string;
birth_date: string;
addresses: Array<{ state: string; city: string }>;
};

type ResponseProfileData = {
id: number;
first_name: string;
last_name: string;
middle_name: string | null;
birth_date: string;
first_names: string[];
middle_names: string[];
last_names: string[];
phone_numbers: string[];
emails: string[];
addresses: Array<{
id: number;
profile_id: number;
state: string;
city: string;
address_line: string | null;
zip: string | null;
created_at: string;
updated_at: string;
url: string;
}>;
status: "active" | "inactive";
created_at: string;
updated_at: string;
url: string;
};
import { MOCK_TIME } from "../config/config.ts";
import {
ResponseProfileData,
RequestProfileData,
} from "../config/userObject.ts";
import { NextRequest, NextResponse } from "next/server";
import { randomInt } from "crypto";

// Mock API endpoint
export default function POST(req: NextApiRequest, res: NextApiResponse) {
export async function POST(req: NextRequest) {
//TODO: mock out all URLs
const profileId = randomInt(1000, 10000);
try {
const requestProfile: RequestProfileData = JSON.parse(req.body);

if (req.body === null) {
return NextResponse.json({ error: "Invalid request - without body" });
}
const requestProfile: RequestProfileData = await req.json();
// Mock response object
const responseProfile: ResponseProfileData = {
id: MOCK_PROFILE_ID, //Random Mock id
id: profileId,
first_name: requestProfile.first_name,
last_name: requestProfile.last_name,
middle_name: requestProfile.middle_name,
Expand All @@ -60,27 +32,27 @@ export default function POST(req: NextApiRequest, res: NextApiResponse) {
phone_numbers: [],
emails: [],
addresses: requestProfile.addresses.map((addr, index) => ({
id: MOCK_PROFILE_ID + index, // Mocked IDs for addresses
profile_id: MOCK_PROFILE_ID,
id: profileId + index, // Mocked IDs for addresses
profile_id: profileId,
state: addr.state,
city: addr.city,
address_line: null,
zip: null,
created_at: MOCK_TIME,
updated_at: MOCK_TIME,
url: `https://api.onerep.com/profiles/${MOCK_PROFILE_ID}/addresses/${MOCK_PROFILE_ID + index}`,
url: `${process.env.ONEREP_API_BASE}/profiles/${profileId}/addresses/${profileId + index}`,
})),
status: "inactive", //assuming status is active
status: "active", //assuming status is active
created_at: MOCK_TIME,
updated_at: MOCK_TIME,
url: `https://api.onerep.com/profiles/${MOCK_PROFILE_ID}`,
url: `${process.env.ONEREP_API_BASE}/profiles/${profileId}`,
};

res.status(201).json(responseProfile);
return NextResponse.json(responseProfile, { status: 201 });
} catch (error) {
console.error("Failed to process request:", error);
res
.status(400)
.json({ error: "Bad Request: Invalid JSON or incorrect data structure" });
return NextResponse.json(
{ error: "Bad Request: Invalid JSON or incorrect data structure" },
{ status: 403 },
);
}
}
Loading
Loading