Skip to content

Commit

Permalink
chore: feature-branch review adjustments (#254)
Browse files Browse the repository at this point in the history
[AB#41699]
  • Loading branch information
AxTrusov authored Mar 6, 2024
1 parent 8060cc3 commit da8f67d
Show file tree
Hide file tree
Showing 16 changed files with 479 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ describe('ChannelPublishEventHandler', () => {
}).run(ctx.ownerPool);
expect(channel).toEqual<channel.JSONSelectable>({
id: channelId,
title: message.payload.title,
description: message.payload.description ?? null,
title: payload.title,
description: payload.description ?? null,
dash_stream_url: null,
hls_stream_url: null,
key_id: null,
Expand All @@ -59,21 +59,22 @@ describe('ChannelPublishEventHandler', () => {
},
{ columns: ['height', 'width', 'path', 'type'] },
).run(ctx.ownerPool);
const { id: imageId, ...messageImage } = message.payload.images![0];
const { id: imageId, ...messageImage } = payload.images![0];
expect(image).toMatchObject(messageImage);
});

test('An existing channel is republished', async () => {
// Arrange
const message = createChannelPublishedMessage(uuid());
const channelId = getChannelId(message.payload.id);
const payload = message.payload;
const channelId = getChannelId(payload.id);
await insert('channel', {
id: channelId,
title: 'Old title',
dash_stream_url: 'https://axinom-test-origin.com/channel-1.isml/.mpd',
hls_stream_url: 'https://axinom-test-origin.com/channel-1.isml/.m3u8',
}).run(ctx.ownerPool);
message.payload.title = 'New title';
payload.title = 'New title';

// Act
await ctx.executeGqlSql(async (txn) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('CollectionPublishEventHandler', () => {

const localizations = await select(
'collection_localizations',
{ collection_id: message.payload.content_id },
{ collection_id: payload.content_id },
{
columns: [
'title',
Expand All @@ -98,7 +98,7 @@ describe('CollectionPublishEventHandler', () => {
},
).run(ctx.ownerPool);
expect(localizations).toIncludeSameMembers(
message.payload.localizations.map(({ language_tag, ...other }) => ({
payload.localizations.map(({ language_tag, ...other }) => ({
...other,
locale: language_tag,
})),
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('CollectionPublishEventHandler', () => {
id: payload.content_id,
}).run(ctx.ownerPool);

expect(collection?.tags).toEqual(message.payload.tags);
expect(collection?.tags).toEqual(payload.tags);
const localizations = await select(
'collection_localizations',
{ collection_id: 'collection-1' },
Expand All @@ -145,7 +145,7 @@ describe('CollectionPublishEventHandler', () => {
},
).run(ctx.ownerPool);
expect(localizations).toIncludeSameMembers(
message.payload.localizations.map(({ language_tag, ...other }) => ({
payload.localizations.map(({ language_tag, ...other }) => ({
...other,
locale: language_tag,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('MoviePublishEventHandler', () => {
},
).run(ctx.ownerPool);
expect(localizations).toIncludeSameMembers(
message.payload.localizations.map(({ language_tag, ...other }) => ({
payload.localizations.map(({ language_tag, ...other }) => ({
...other,
locale: language_tag,
})),
Expand All @@ -142,6 +142,7 @@ describe('MoviePublishEventHandler', () => {
is_default_locale: true,
}).run(ctx.ownerPool);
const message = createMoviePublishedMessage('movie-1');
const payload = message.payload;

// Act
await ctx.executeGqlSql(async (txn) => {
Expand All @@ -150,7 +151,7 @@ describe('MoviePublishEventHandler', () => {

// Assert
const movie = await selectOne('movie', {
id: message.payload.content_id,
id: payload.content_id,
}).run(ctx.ownerPool);

expect(movie?.original_title).toEqual('Movie title');
Expand All @@ -168,7 +169,7 @@ describe('MoviePublishEventHandler', () => {
},
).run(ctx.ownerPool);
expect(localizations).toIncludeSameMembers(
message.payload.localizations.map(({ language_tag, ...other }) => ({
payload.localizations.map(({ language_tag, ...other }) => ({
...other,
locale: language_tag,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('EpisodePublishEventHandler', () => {
expect(licenses).toMatchObject(licenses);
const localizations = await select(
'episode_localizations',
{ episode_id: message.payload.content_id },
{ episode_id: payload.content_id },
{
columns: [
'title',
Expand All @@ -108,7 +108,7 @@ describe('EpisodePublishEventHandler', () => {
},
).run(ctx.ownerPool);
expect(localizations).toIncludeSameMembers(
message.payload.localizations.map(({ language_tag, ...other }) => ({
payload.localizations.map(({ language_tag, ...other }) => ({
...other,
locale: language_tag,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ describe('SeasonPublishEventHandler', () => {
);
const localizations = await select(
'season_localizations',
{ season_id: message.payload.content_id },
{ season_id: payload.content_id },
{
columns: ['description', 'synopsis', 'locale', 'is_default_locale'],
},
).run(ctx.ownerPool);
expect(localizations).toIncludeSameMembers(
message.payload.localizations.map(({ language_tag, ...other }) => ({
payload.localizations.map(({ language_tag, ...other }) => ({
...other,
locale: language_tag,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { all, insert, select, selectOne } from 'zapatos/db';
import { tvshow_genre } from 'zapatos/schema';
import { DEFAULT_LOCALE_TAG } from '../../../common';
import {
createGenrePublishedMessage,
createTestContext,
createTvshowGenrePublishedMessage,
ITestContext,
} from '../../../tests/test-utils';
import { TvshowGenresPublishedEventHandler } from './tvshow-genres-published-event-handler';
Expand All @@ -30,7 +30,7 @@ describe('TvshowGenrePublishEventHandler', () => {
describe('onMessage', () => {
test('A new tvshow genre is published', async () => {
// Arrange
const message = createGenrePublishedMessage('tvshow_genre-1');
const message = createTvshowGenrePublishedMessage('tvshow_genre-1');

// Act
await ctx.executeGqlSql(async (txn) => {
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('TvshowGenrePublishEventHandler', () => {
locale: DEFAULT_LOCALE_TAG,
is_default_locale: true,
}).run(ctx.ownerPool);
const message = createGenrePublishedMessage(contentId);
const message = createTvshowGenrePublishedMessage(contentId);

// Act
await ctx.executeGqlSql(async (txn) => {
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('TvshowGenrePublishEventHandler', () => {
locale: DEFAULT_LOCALE_TAG,
is_default_locale: true,
}).run(ctx.ownerPool);
const message = createGenrePublishedMessage('tvshow_genre-2');
const message = createTvshowGenrePublishedMessage('tvshow_genre-2');

// Act
await ctx.executeGqlSql(async (txn) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('TvshowPublishEventHandler', () => {
);
const localizations = await select(
'tvshow_localizations',
{ tvshow_id: message.payload.content_id },
{ tvshow_id: payload.content_id },
{
columns: [
'title',
Expand All @@ -121,7 +121,7 @@ describe('TvshowPublishEventHandler', () => {
},
).run(ctx.ownerPool);
expect(localizations).toIncludeSameMembers(
message.payload.localizations.map(({ language_tag, ...other }) => ({
payload.localizations.map(({ language_tag, ...other }) => ({
...other,
locale: language_tag,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function createMovieGenresPublishedMessage(
});
}

export function createGenrePublishedMessage(
export function createTvshowGenrePublishedMessage(
contentId: string,
): TypedTransactionalMessage<TvshowGenresPublishedEvent> {
return createMessage({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Broker } from '@axinom/mosaic-message-bus';
import { LocalizationServiceMultiTenantMessagingSettings } from '@axinom/mosaic-messages';
import {
DeclareEntityDefinitionCommand,
LocalizationServiceMultiTenantMessagingSettings,
} from '@axinom/mosaic-messages';
import { StoreOutboxMessage } from '@axinom/mosaic-transactional-inbox-outbox';
import { ClientBase } from 'pg';
import { Config, requestServiceAccountToken } from '../common';
import { getCollectionLocalizationEntityDefinitions } from './collections';
import { getMovieLocalizationEntityDefinitions } from './movies';
import { getTvshowLocalizationEntityDefinitions } from './tvshows';

export const registerLocalizationEntityDefinitions = async (
broker: Broker,
storeOutboxMessage: StoreOutboxMessage,
loginClient: ClientBase,
config: Config,
): Promise<void> => {
const accessToken = await requestServiceAccountToken(config);
Expand All @@ -27,16 +32,21 @@ export const registerLocalizationEntityDefinitions = async (
...collectionDefinitions,
];
for (const definition of definitions) {
await broker.publish(
await storeOutboxMessage<DeclareEntityDefinitionCommand>(
config.environmentId,
settings,
definition,
{ auth_token: accessToken },
loginClient,
{
routingKey: settings.getEnvironmentRoutingKey({
tenantId: config.tenantId,
environmentId: config.environmentId,
}),
envelopeOverrides: {
auth_token: accessToken,
},
options: {
routingKey: settings.getEnvironmentRoutingKey({
tenantId: config.tenantId,
environmentId: config.environmentId,
}),
},
},
);
}
Expand Down
10 changes: 10 additions & 0 deletions services/media/service/src/domains/register-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { StoreOutboxMessage } from '@axinom/mosaic-transactional-inbox-outbox';
import { IsolationLevel } from 'zapatos/db';
import { Config } from '../common';
import { registerImageTypes } from './register-image-types';
import { registerLocalizationEntityDefinitions } from './register-localization-entity-definitions';
import { registerVideoCuePointTypes } from './register-video-cue-point-types';

export const registerTypes = async (
Expand All @@ -20,6 +21,15 @@ export const registerTypes = async (

// Register video cue point types used in media service.
await registerVideoCuePointTypes(storeOutboxMessage, loginClient, config);

if (config.isLocalizationEnabled) {
// Register localization entity definitions for the media service localizable entities.
await registerLocalizationEntityDefinitions(
storeOutboxMessage,
loginClient,
config,
);
}
},
);
};
Loading

0 comments on commit da8f67d

Please sign in to comment.