Skip to content

Commit

Permalink
#519338 refactoring: moved constants
Browse files Browse the repository at this point in the history
  • Loading branch information
sc-ruslanmatkovskyi committed Mar 31, 2022
1 parent c383d7e commit e3206c2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { NextRequest, NextResponse } from 'next/server';
import { RedirectType, GraphQLRedirectsService } from '@sitecore-jss/sitecore-jss-nextjs';
import {
RedirectType,
GraphQLRedirectsService,
REDIRECT_TYPE_PREFIX,
REDIRECT_TYPE_DEFAULT,
} from '@sitecore-jss/sitecore-jss-nextjs';
import config from 'temp/config';
import { MiddlewarePlugin } from '..';

const REDIRECT_TYPE_PREFIX = 'REDIRECT_';
const REDIRECT_TYPE_DEFAULT = 301;

class RedirectsPlugin implements MiddlewarePlugin {
private redirectsService: GraphQLRedirectsService;
order = 0;
Expand Down
2 changes: 2 additions & 0 deletions packages/sitecore-jss-nextjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export {
RedirectsQueryResult,
GraphQLRedirectsService,
GraphQLRedirectsServiceConfig,
REDIRECT_TYPE_PREFIX,
REDIRECT_TYPE_DEFAULT,
} from '@sitecore-jss/sitecore-jss/site';
export { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('GraphQLRedirectsService', () => {
nock.cleanAll();
});

const mockRobotsRequest = (siteName?: string) => {
const mockRedirectsRequest = (siteName?: string) => {
nock(endpoint)
.post('/')
.reply(
Expand All @@ -54,7 +54,7 @@ describe('GraphQLRedirectsService', () => {

describe('fetch redirects from site by graphql', () => {
it('should get error if redirects has empty siteName', async () => {
mockRobotsRequest();
mockRedirectsRequest();

const service = new GraphQLRedirectsService({ endpoint, apiKey, siteName: '' });
await service.fetchRedirects().catch((error: Error) => {
Expand All @@ -65,7 +65,7 @@ describe('GraphQLRedirectsService', () => {
});

it('should get redirects', async () => {
mockRobotsRequest(siteName);
mockRedirectsRequest(siteName);

const service = new GraphQLRedirectsService({ endpoint, apiKey, siteName });
const result = await service.fetchRedirects();
Expand All @@ -76,7 +76,7 @@ describe('GraphQLRedirectsService', () => {
});

it('should get no redirects', async () => {
mockRobotsRequest();
mockRedirectsRequest();

const service = new GraphQLRedirectsService({ endpoint, apiKey, siteName });
const result = await service.fetchRedirects();
Expand Down
3 changes: 2 additions & 1 deletion packages/sitecore-jss/src/site/graphql-redirects-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { GraphQLClient, GraphQLRequestClient } from '../graphql';
import debug from '../debug';

export const PREFIX_REDIRECT_TYPE = 'REDIRECT_';
export const REDIRECT_TYPE_PREFIX = 'REDIRECT_';
export const REDIRECT_TYPE_DEFAULT = 301;

export type RedirectType = {
pattern: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/sitecore-jss/src/site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export {
export {
RedirectType,
RedirectsQueryResult,
REDIRECT_TYPE_PREFIX,
REDIRECT_TYPE_DEFAULT,
GraphQLRedirectsService,
GraphQLRedirectsServiceConfig,
} from './graphql-redirects-service';

0 comments on commit e3206c2

Please sign in to comment.