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

MIJN-9932-Bug - Remove unneeded script, fix test #1691

Merged
merged 2 commits into from
Jan 7, 2025
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
15 changes: 6 additions & 9 deletions src/server/services/adoptable-trash-containers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { fetchAdoptableTrashContainers } from './adoptable-trash-containers';
import { fetchBRP } from './brp';
import { fetchDataset } from './buurt/buurt';
import { fetchMyLocation } from './my-locations';
import {
generateRandomPoints,
getAuthProfileAndToken,
} from '../../testing/utils';
import { getAuthProfileAndToken } from '../../testing/utils';
import {
DEFAULT_LAT,
DEFAULT_LNG,
Expand Down Expand Up @@ -40,11 +37,11 @@ describe('fetchAdoptableTrashContainers', () => {
(fetchBRP as Mock).mockResolvedValue(brpApiResponse);
(fetchMyLocation as Mock).mockResolvedValue(locationApiResponse);

const [coord] = generateRandomPoints(
{ lat: DEFAULT_LAT, lng: DEFAULT_LNG },
90, // 90 meters
1
);
const DISTANCE_ADDED = 0.0001;
const coord = {
lat: DEFAULT_LAT + DISTANCE_ADDED,
lng: DEFAULT_LNG + DISTANCE_ADDED,
};

(fetchDataset as Mock).mockResolvedValue(
apiSuccessResult({
Expand Down
48 changes: 0 additions & 48 deletions src/testing/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { millisecondsToSeconds } from 'date-fns';
import { Request, Response } from 'express';
import { LatLngLiteral } from 'leaflet';
import nock from 'nock';
import UID from 'uid-safe';

Expand Down Expand Up @@ -144,50 +143,3 @@ export async function getReqMockWithOidc(

export const DEV_JWT =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';

/**
* Generates number of random geolocation points given a center and a radius.
* @param {Object} center A JS object with lat and lng attributes.
* @param {number} radius Radius in meters.
* @param {number} count Number of points to generate.
* @return {array} Array of Objects with lat and lng attributes.
*/
export function generateRandomPoints(
center: LatLngLiteral,
radius: number,
count: number
) {
const points = [];
for (let i = 0; i < count; i++) {
points.push(generateRandomPoint(center, radius));
}
return points;
}

/**
* Generates number of random geolocation points given a center and a radius.
* Reference URL: http://goo.gl/KWcPE.
* @param {Object} center A JS object with lat and lng attributes.
* @param {number} radius Radius in meters.
* @return {Object} The generated random points as JS object with lat and lng attributes.
*/
export function generateRandomPoint(center: LatLngLiteral, radius: number) {
const x0 = center.lng;
const y0 = center.lat;
// Convert Radius from meters to degrees.
// eslint-disable-next-line no-magic-numbers
const rd = radius / 111300;

const u = Math.random();
const v = Math.random();

const w = rd * Math.sqrt(u);
const t = 2 * Math.PI * v;
const x = w * Math.cos(t);
const y = w * Math.sin(t);

const xp = x / Math.cos(y0);

// Resulting point.
return { lat: y + y0, lng: xp + x0 };
}
Loading