Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ticketmaster/allure-mock

Package Overview
Dependencies
Maintainers
0
Versions
518
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ticketmaster/allure-mock

Allure common mocking solution library

  • 6.0.10-alpha.1
  • npm
  • Socket score

Version published
Weekly downloads
457
decreased by-61.73%
Maintainers
0
Weekly downloads
 
Created
Source

@ticketmaster/allure-mock

Allure common mocking solution library.


This library is a collection of shared mocking middlewares to mock shared services inside an Allure project.

Usage

1. Install dependencies

First, you need to install the dependencies.

yarn add @ticketmaster/allure-mock -D

2. Create the mock server creator

If you don't already have one, you have to create a function to instantiate a mock server. This function will be called later if we need to mock calls.

We recommend to put this file at the root of your src folder and call it middleware.ts.

// src/middleware.ts

import { NextRequest, NextResponse } from "next/server";
import createMiddleware from "next-intl/middleware";
import { AVAILABLE_LOCALES, DEFAULT_LOCALE } from "./config";
import { identityMockApi } from "@ticketmaster/allure-mock";

export function middleware(request: NextRequest) {
const handleI18nRouting = createIntlMiddleware({
  locales: AVAILABLE_LOCALES,
  defaultLocale: DEFAULT_LOCALE,
  localeDetection: true,
});

const response = handleI18nRouting(request);

export const config = {
  matcher: [
    "/((?!_next).*)", // do not localize next.js paths
    `/api/v1/:path*`, // Limit the middleware to paths starting with `/api/v1`
  ],
};

export function middleware(req: NextRequest) {
  if (process.env.NODE_ENV === "development") {
    const { pathname } = request.nextUrl;
    const endpointsMap: {
      [key: string]: (nextRequest: NextRequest) => Promise<NextResponse>;
    } = {
      "/sessions/logout": identityMockApi,
      "/systems": identityMockApi,
      "/token/refresh": identityMockApi,
      "/token/verify": identityMockApi,
    };

    if (pathname.startsWith("/api/v1")) {
      const path = pathname.split("/api/v1");
      const endpoint = path.length > 0 ? path[1] : "";

      for (const [key, value] of Object.entries(endpointsMap)) {
        if (endpoint.match(key)) {
          return value(request);
        }
      }
    }
  }

  return NextResponse.next();
}

FAQs

Package last updated on 04 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc