Skip to content

Commit

Permalink
N21-2103 fix media license repo test
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonNicholasCap committed Dec 16, 2024
1 parent 8b191f3 commit 78113e1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
1 change: 0 additions & 1 deletion apps/server/src/modules/media-source/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { MediaSource } from './domain';
export { MediaSourceService } from './service';
export { mediaSourceFactory } from './testing';
3 changes: 3 additions & 0 deletions apps/server/src/modules/media-source/testing/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { mediaSourceFactory } from './media-source.factory';
export { mediaSourceEntityFactory } from './media-source-entity.factory';
export { mediaSourceBasicConfigEmbeddableFactory } from './media-source-basic-auth-config.embeddable.factory';
export { mediaSourceOAuthConfigEmbeddableFactory } from './media-source-oauth-config.embeddable.factory';
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import { EntityManager } from '@mikro-orm/mongodb';
import { Test, TestingModule } from '@nestjs/testing';
import { User as UserEntity } from '@shared/domain/entity';
import { cleanupCollections, userFactory } from '@shared/testing';
import { mediaSourceOAuthConfigEmbeddableFactory } from '@src/modules/media-source/testing/media-source-oauth-config.embeddable.factory';
import { mediaSourceEntityFactory } from '@src/modules/media-source/testing/media-source-entity.factory';
import { mediaSourceFactory } from '@src/modules/media-source/testing/media-source.factory';
import { MediaSourceConfigMapper } from '@src/modules/media-source/repo';
import { MediaSourceEntity, MediaSourceOauthConfigEmbeddable } from '@src/modules/media-source/entity';
import { MediaSource } from '@modules/media-source';
import { MediaSourceEntity } from '@modules/media-source/entity';
import { MediaSourceConfigMapper } from '@modules/media-source/repo';
import {
mediaSourceFactory,
mediaSourceEntityFactory,
mediaSourceBasicConfigEmbeddableFactory,
mediaSourceOAuthConfigEmbeddableFactory,
} from '@modules/media-source/testing';
import { MediaUserLicense } from '../domain';
import { MediaUserLicenseEntity } from '../entity';
import { mediaUserLicenseEntityFactory, mediaUserLicenseFactory } from '../testing';
import { MediaUserLicenseRepo } from './media-user-license.repo';
import { MediaSource } from '@src/modules/media-source/domain';

describe(MediaUserLicenseRepo.name, () => {
let module: TestingModule;
Expand Down Expand Up @@ -41,8 +44,9 @@ describe(MediaUserLicenseRepo.name, () => {
describe('when searching for a users media licences', () => {
const setup = async () => {
const user: UserEntity = userFactory.build();
const config: MediaSourceOauthConfigEmbeddable = mediaSourceOAuthConfigEmbeddableFactory.build();
const mediaSource: MediaSourceEntity = mediaSourceEntityFactory.build({ oauthConfig: config });
const basicAuthConfig = mediaSourceBasicConfigEmbeddableFactory.build();
const oauthConfig = mediaSourceOAuthConfigEmbeddableFactory.build();
const mediaSource: MediaSourceEntity = mediaSourceEntityFactory.build({ basicAuthConfig, oauthConfig });
const mediaUserLicense: MediaUserLicenseEntity = mediaUserLicenseEntityFactory.build({ user, mediaSource });
const otherMediaUserLicense: MediaUserLicenseEntity = mediaUserLicenseEntityFactory.build();

Expand All @@ -54,12 +58,13 @@ describe(MediaUserLicenseRepo.name, () => {
user,
mediaUserLicense,
mediaSource,
config,
basicAuthConfig,
oauthConfig,
};
};

it('should return user licenses for user', async () => {
const { user, mediaUserLicense, mediaSource, config } = await setup();
const { user, mediaUserLicense, mediaSource, basicAuthConfig, oauthConfig } = await setup();

const result: MediaUserLicense[] = await repo.findMediaUserLicensesForUser(user.id);

Expand All @@ -74,7 +79,8 @@ describe(MediaUserLicenseRepo.name, () => {
name: mediaSource.name,
sourceId: mediaSource.sourceId,
format: mediaSource.format,
oauthConfig: MediaSourceConfigMapper.mapOauthConfigToDo(config),
oauthConfig: MediaSourceConfigMapper.mapOauthConfigToDo(oauthConfig),
basicAuthConfig: MediaSourceConfigMapper.mapBasicConfigToDo(basicAuthConfig),
}),
}),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class MediaUserLicenseRepo extends BaseDomainObjectRepo<MediaUserLicense,
oauthConfig: entity.mediaSource.oauthConfig
? MediaSourceConfigMapper.mapOauthConfigToDo(entity.mediaSource.oauthConfig)
: undefined,
basicAuthConfig: entity.mediaSource.basicAuthConfig
? MediaSourceConfigMapper.mapBasicConfigToDo(entity.mediaSource.basicAuthConfig)
: undefined,
});
}

Expand Down

0 comments on commit 78113e1

Please sign in to comment.