Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nkowaokwu/igbo_api into ec/transl…
Browse files Browse the repository at this point in the history
…ation-endpoint
  • Loading branch information
ebubae committed Oct 31, 2024
2 parents dc69197 + 714df73 commit 75a662a
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 121 deletions.
96 changes: 0 additions & 96 deletions __tests__/shared/fixtures.ts

This file was deleted.

22 changes: 13 additions & 9 deletions src/APIs/__tests__/FlagsAPI.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { dialectFixture, exampleFixture, wordFixture } from '../../../__tests__/shared/fixtures';
import {
dialectFixture,
outgoingExampleFixture,
outgoingWordFixture,
} from '../../__tests__/shared/fixtures';
import LanguageEnum from '../../shared/constants/LanguageEnum';
import { SuggestionSourceEnum } from '../../shared/constants/SuggestionSourceEnum';
import { handleWordFlags } from '../FlagsAPI';

describe('FlagsAPI', () => {
const words = [
wordFixture({
outgoingWordFixture({
word: 'first word',
examples: [
exampleFixture({
outgoingExampleFixture({
source: { text: 'first example', language: LanguageEnum.IGBO, pronunciations: [] },
}),
exampleFixture({
outgoingExampleFixture({
source: {
text: 'second example',
language: LanguageEnum.IGBO,
pronunciations: [],
},
origin: SuggestionSourceEnum.INTERNAL,
}),
exampleFixture({
outgoingExampleFixture({
source: {
text: 'second example',
language: LanguageEnum.IGBO,
Expand All @@ -29,14 +33,14 @@ describe('FlagsAPI', () => {
}),
],
}),
wordFixture({
outgoingWordFixture({
word: 'second word',
dialects: [dialectFixture({ word: 'second-word-dialect' })],
}),
wordFixture({
outgoingWordFixture({
word: 'third word',
stems: [wordFixture({ word: 'first stem' })],
relatedTerms: [wordFixture({ word: 'first related term' })],
stems: [outgoingWordFixture({ word: 'first stem' })],
relatedTerms: [outgoingWordFixture({ word: 'first related term' })],
}),
];

Expand Down
98 changes: 96 additions & 2 deletions src/__tests__/shared/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { capitalize } from 'lodash';
import { WordDialect } from '../../types/word';
import { NextFunction, Request, Response } from 'express';
import { Flags } from '../../controllers/utils/types';
import LanguageEnum from '../../shared/constants/LanguageEnum';
import WordAttributeEnum from '../../shared/constants/WordAttributeEnum';
import { SuggestionSourceEnum } from '../../shared/constants/SuggestionSourceEnum';
import WordClass from '../../shared/constants/WordClass';
import {
Expand All @@ -7,15 +12,21 @@ import {
IncomingWord,
DeveloperDocument,
DeveloperUsage,
OutgoingExample,
OutgoingWord,
} from '../../types';
import { Types } from 'mongoose';
import AccountStatus from '../../shared/constants/AccountStatus';
import ApiType from '../../shared/constants/ApiType';
import Plan from '../../shared/constants/Plan';

interface RequestOptions {
noAuthorizationHeader?: boolean;
}

export const documentId = new Types.ObjectId('569ed8269353e9f4c51617aa');

export const wordFixture = (wordData: Partial<IncomingWord>) => ({
export const incomingWordFixture = (wordData: Partial<IncomingWord>) => ({
definitions: [],
dialects: [],
tags: [],
Expand Down Expand Up @@ -54,7 +65,7 @@ export const definitionFixture = (definitionData: Partial<Definition>) => ({
...definitionData,
});

export const exampleFixture = (exampleData: Partial<IncomingExample>) => ({
export const incomingExampleFixture = (exampleData: Partial<IncomingExample>) => ({
source: { text: '', language: LanguageEnum.UNSPECIFIED, pronunciations: [] },
translations: [{ text: '', language: LanguageEnum.UNSPECIFIED, pronunciations: [] }],
meaning: '',
Expand Down Expand Up @@ -94,3 +105,86 @@ export const developerUsageFixture = (developerFixture: Partial<DeveloperUsage>)
},
...developerFixture,
});

export const outgoingWordFixture = (data?: Partial<OutgoingWord>) => ({
attributes: Object.values(WordAttributeEnum).reduce(
(finalAttributes, attribute) => ({ ...finalAttributes, [attribute]: false }),
{}
),
conceptualWord: '',
frequency: 1,
hypernyms: [],
hyponyms: [],
pronunciation: '',
relatedTerms: [],
stems: [],
updatedAt: new Date(),
variations: [],
word: '',
wordPronunciation: '',
definitions: [],
dialects: [],
tags: [],
id: `${new Types.ObjectId()}`,
...data,
});

export const outgoingExampleFixture = (data?: Partial<OutgoingExample>) => ({
id: `${new Types.ObjectId()}`,
associatedDefinitionsSchemas: [],
associatedWords: [],
source: { text: '', language: LanguageEnum.UNSPECIFIED, pronunciations: [] },
translations: [{ text: '', language: LanguageEnum.UNSPECIFIED, pronunciations: [] }],
meaning: '',
nsibidi: '',
nsibidiCharacters: [],
pronunciations: [],
origin: SuggestionSourceEnum.INTERNAL,
updatedAt: new Date(),
...data,
});

export const dialectFixture = (data?: Partial<WordDialect>) => ({
dialects: [],
id: `${new Types.ObjectId()}`,
pronunciation: '',
variations: [],
word: '',
...data,
});

export const flagsFixture = (data?: Partial<Flags>) => ({
examples: false,
dialects: false,
resolve: false,
style: '',
...data,
});

export const requestFixture = (
{
body = {},
params = {},
headers = {},
}: {
body?: { [key: string]: string },
params?: { [key: string]: string },
headers?: { [key: string]: string },
} = {},
options?: RequestOptions
): Request => ({
body,
params,
headers,
query: {},
// @ts-expect-error get
get: (header: string) => headers[header] || headers[capitalize(header)],
});
export const statusSendMock = jest.fn();
export const responseFixture = (): Response => ({
// @ts-expect-error status
status: jest.fn(() => ({ send: statusSendMock })),
send: jest.fn(),
redirect: jest.fn(),
});
export const nextFunctionFixture = (): NextFunction => jest.fn();
2 changes: 1 addition & 1 deletion src/controllers/__tests__/developers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
requestFixture,
responseFixture,
nextFunctionFixture,
} from '../../../__tests__/shared/fixtures';
} from '../../__tests__/shared/fixtures';
import {
getDeveloper,
getDeveloperByEmail,
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/__tests__/examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { exampleFixture } from '../../__tests__/shared/fixtures';
import { incomingExampleFixture } from '../../__tests__/shared/fixtures';
import LanguageEnum from '../../shared/constants/LanguageEnum';
import { convertToV1Example } from '../examples';

describe('examples', () => {
it('converts example pronunciations to pronunciation for v1', () => {
const example = exampleFixture({
const example = incomingExampleFixture({
source: {
text: 'igbo',
language: LanguageEnum.IGBO,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/__tests__/speechToText.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
requestFixture,
responseFixture,
nextFunctionFixture,
} from '../../../__tests__/shared/fixtures';
} from '../../__tests__/shared/fixtures';
import { getTranscription } from '../speechToText';
import { fetchBase64Data } from '../utils/fetchBase64Data';

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/__tests__/stripe.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jest.mock('stripe');
import { requestFixture, responseFixture } from '../../../__tests__/shared/fixtures';
import { requestFixture, responseFixture } from '../../__tests__/shared/fixtures';
import { postCheckoutSession, postPortalSession } from '../stripe';

describe('Credentials', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/stripe/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
nextFunctionFixture,
requestFixture,
responseFixture,
} from '../../../../__tests__/shared/fixtures';
} from '../../../__tests__/shared/fixtures';
import {
handleCustomerSubscriptionCreated,
handleCustomerSubscriptionDeleted,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import Version from '../../../shared/constants/Version';
import WordClass from '../../../shared/constants/WordClass';
import { definitionFixture, wordFixture } from '../../../__tests__/shared/fixtures';
import { definitionFixture, incomingWordFixture } from '../../../__tests__/shared/fixtures';
import minimizeVerbsAndSuffixes from '../minimizeVerbsAndSuffixes';
import WordClassEnum from '../../../shared/constants/WordClassEnum';

describe('minimizeVerbsAndSuffixes', () => {
it('minimizes the verbs and suffixes to include basic fields', () => {
const words = [
wordFixture({
incomingWordFixture({
word: 'first word',
definitions: [definitionFixture({})],
stems: [],
relatedTerms: [],
id: '123',
}),
wordFixture({
incomingWordFixture({
word: 'second word',
definitions: [definitionFixture({ wordClass: WordClassEnum.ADV })],
stems: [],
relatedTerms: [],
id: '456',
}),
wordFixture({
incomingWordFixture({
word: 'third word',
definitions: [definitionFixture({ wordClass: WordClassEnum.PREP })],
stems: [],
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/utils/__tests__/queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import createRegExp from '../../../shared/utils/createRegExp';
import { searchExamplesRegexQuery } from '../queries';
import { flagsFixture } from '../../../../__tests__/shared/fixtures';
import { flagsFixture } from '../../../__tests__/shared/fixtures';
import { SuggestionSourceEnum } from '../../../shared/constants/SuggestionSourceEnum';

describe('queries', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/__tests__/authorizeCheckoutSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
requestFixture,
responseFixture,
nextFunctionFixture,
} from '../../../__tests__/shared/fixtures';
} from '../../__tests__/shared/fixtures';

describe('authorizeCheckoutSession', () => {
it('authorizes the current checkout session', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/__tests__/authorizePortalSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
requestFixture,
responseFixture,
nextFunctionFixture,
} from '../../../__tests__/shared/fixtures';
} from '../../__tests__/shared/fixtures';

describe('authorizePortalSession', () => {
it('authorizes the current portal session', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/__tests__/developerAuthorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
responseFixture,
nextFunctionFixture,
statusSendMock,
} from '../../../__tests__/shared/fixtures';
} from '../../__tests__/shared/fixtures';

jest.mock('firebase-admin');

Expand Down

0 comments on commit 75a662a

Please sign in to comment.