Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
refactor(yt:backend): moved metadata arbs info yt:shared package
Browse files Browse the repository at this point in the history
  • Loading branch information
ascariandrea committed Nov 22, 2022
1 parent 1b39f99 commit f144659
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 37 deletions.
13 changes: 10 additions & 3 deletions platforms/storybook/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@
"moduleResolution": "node",
"isolatedModules": true,
"paths": {
"@shared/*": [
"../../../packages/shared/src/*"
]
"@shared/*": ["../../../packages/shared/src/*"]
}
},
"references": [
{
"path": "../../packages/shared"
},
{
"path": "../../packages/taboule"
},
{
"path": "../yttrex/shared"
},
{
"path": "../tktrex/shared"
}
],
"include": ["./src"],
Expand Down
60 changes: 30 additions & 30 deletions platforms/yttrex/backend/routes/__tests__/ads.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* eslint-disable import/first */
// mock curly module
jest.mock("../../lib/curly");
jest.mock("fetch-opengraph");

import { VideoArb } from "@shared/arbitraries/Video.arb";
import { AdArb } from "../../tests/arbitraries/Ad.arb";
import { VideoMetadataArb } from "../../tests/arbitraries/Metadata.arb";
import { fc } from "@shared/test";
import { v4 as uuid } from "uuid";
import { GetTest, Test } from "../../tests/Test";
import { sub } from "date-fns";

describe("The ADS API", () => {
jest.mock('../../lib/curly');
jest.mock('fetch-opengraph');

import { VideoArb } from '@shared/arbitraries/Video.arb';
import { AdArb } from '../../tests/arbitraries/Ad.arb';
import { VideoMetadataArb } from '@yttrex/shared/arbitraries/Metadata.arb';
import { fc } from '@shared/test';
import { v4 as uuid } from 'uuid';
import { GetTest, Test } from '../../tests/Test';
import { sub } from 'date-fns';

describe('The ADS API', () => {
const channelId = uuid();
let test: Test;

Expand All @@ -23,8 +23,8 @@ describe("The ADS API", () => {
await test.mongo.close();
});

describe("Get by channel", () => {
it("fails using channelId without date range", async () => {
describe('Get by channel', () => {
it('fails using channelId without date range', async () => {
const { body } = await test.app
.get(`/api/v2/ad/channel/${channelId}`)
.query({})
Expand All @@ -41,7 +41,7 @@ describe("The ADS API", () => {
const { body } = await test.app
.get(`/api/v2/ad/channel/${channelId}`)
.query({
till: "2022-01-01",
till: '2022-01-01',
})
.expect(500);

Expand All @@ -56,7 +56,7 @@ describe("The ADS API", () => {
const { body } = await test.app
.get(`/api/v2/ad/channel/${channelId}`)
.query({
since: "2022-01-01",
since: '2022-01-01',
})
.expect(500);

Expand All @@ -67,47 +67,47 @@ describe("The ADS API", () => {
});
});

it("succeeds using channelId", async () => {
it('succeeds using channelId', async () => {
const { body } = await test.app
.get(`/api/v2/ad/channel/${channelId}`)
.query({
since: "2020-01-01",
till: "2021-01-01",
since: '2020-01-01',
till: '2021-01-01',
})
.expect(200);

expect(body).toEqual([]);
});
});

describe("Get by video", () => {
describe('Get by video', () => {
const video = fc.sample(VideoArb, 1)[0];

it("fails using wrong videoId", async () => {
it('fails using wrong videoId', async () => {
const { body } = await test.app
.get(`/api/v2/ad/video/fake-id`)
.query({
since: "2020-01-01",
till: "2021-01-01",
since: '2020-01-01',
till: '2021-01-01',
})
.expect(500);

expect(body).toEqual({});
});

it("fails using videoId", async () => {
it('fails using videoId', async () => {
const { body } = await test.app
.get(`/api/v2/ad/video/${video.videoId}`)
.query({
since: "2020-01-01",
till: "2021-01-01",
since: '2020-01-01',
till: '2021-01-01',
})
.expect(200);

expect(body).toEqual([]);
});

it("succeeds using videoId", async () => {
it('succeeds using videoId', async () => {
const videoId = fc.sample(fc.uuid(), 1)[0];
const [metadata] = fc.sample(VideoMetadataArb, 1).map((meta) => ({
...meta,
Expand All @@ -124,7 +124,7 @@ describe("The ADS API", () => {
: ad.sponsoredSite.concat(`/`),
metadataId: metadata.id,
nature: {
type: "video",
type: 'video',
videoId,
},
savingTime: sub(new Date(), { weeks: 3 }),
Expand All @@ -133,13 +133,13 @@ describe("The ADS API", () => {
// insert video
await test.mongo3.insertMany(
test.mongo,
test.config.get("schema").metadata,
test.config.get('schema').metadata,
[metadata]
);
// insert ads
await test.mongo3.insertMany(
test.mongo,
test.config.get("schema").ads,
test.config.get('schema').ads,
ads
);

Expand Down
27 changes: 23 additions & 4 deletions platforms/yttrex/backend/routes/__tests__/public.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,40 @@ jest.mock('fetch-opengraph');
import { fc } from '@shared/test';
import _ from 'lodash';
import { v4 as uuid } from 'uuid';
import {
ParsedInfoArb,
VideoMetadataArb,
} from '../../tests/arbitraries/Metadata.arb';
import { HomeMetadataArb } from '@yttrex/shared/arbitraries/Metadata.arb';
import { GetTest, Test } from '../../tests/Test';
import { HomeMetadataDB } from '../../models/metadata/HomeMetadata';

describe('The Public API', () => {
const channelId = uuid();
let test: Test;
let homes: HomeMetadataDB[];
const publicKey = 'public-key';

beforeAll(async () => {
test = await GetTest();
homes = fc.sample(HomeMetadataArb, 10).map((h) => ({
...h,
publicKey,
savingTime: new Date(),
selected: h.selected as any[],
}));

await test.mongo3.insertMany(
test.mongo,
test.config.get('schema').metadata,
homes
);
});

afterAll(async () => {
await test.mongo3.deleteMany(
test.mongo,
test.config.get('schema').metadata,
{
publicKey: { $eq: publicKey },
}
);
await test.mongo.close();
});

Expand Down

0 comments on commit f144659

Please sign in to comment.