Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EW-1019: TSP Testing #5375

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0ce5351
Add empty line.
mkreuzkam-cap Dec 4, 2024
7bbabe7
log token
mkreuzkam-cap Dec 4, 2024
fcd8d6d
Remove pLimit temporarily for testing.
mkreuzkam-cap Dec 9, 2024
49bfdda
Manual batching of data.
mkreuzkam-cap Dec 9, 2024
628d8c3
Merge branch 'main' into EW-1019
mkreuzkam-cap Dec 9, 2024
397dff6
Fix array size.
mkreuzkam-cap Dec 9, 2024
e4548fc
Better logging.
mkreuzkam-cap Dec 9, 2024
634049c
Merge branch 'main' into EW-1019
mkreuzkam-cap Dec 9, 2024
0f7acca
Even more logs!
mkreuzkam-cap Dec 9, 2024
1c342a0
Logging of errors.
mkreuzkam-cap Dec 10, 2024
a9669a5
Use bulk operations for sync. (Very WIP!!!)
mkreuzkam-cap Dec 11, 2024
3633cc0
EW-1019 Fix Linter warnings
SimoneRadtke-Cap Dec 11, 2024
ac863a7
EW-1019 Fix linter warnings
SimoneRadtke-Cap Dec 11, 2024
551f0e6
Use bulk operations for migration.
mkreuzkam-cap Dec 11, 2024
3c805b4
Merge branch 'main' into EW-1019
mkreuzkam-cap Dec 11, 2024
79c6a7c
EW-1019 Add docker compose file to gitignore
SimoneRadtke-Cap Dec 11, 2024
18217e6
fix linter warning
mkreuzkam-cap Dec 11, 2024
643c843
Bulk migration for students.
mkreuzkam-cap Dec 13, 2024
0a38d25
Merge branch 'main' into EW-1019
mkreuzkam-cap Dec 16, 2024
a04d22d
Use configService directly and don't read values in constructor.
mkreuzkam-cap Dec 16, 2024
c16a7bf
Add batching.
mkreuzkam-cap Dec 16, 2024
92e1b49
Merge branch 'main' into EW-1019
mkreuzkam-cap Dec 17, 2024
7dc774f
remove console log, add comments
mkreuzkam-cap Dec 17, 2024
2587c90
Clean up migration and move into service class.
mkreuzkam-cap Dec 17, 2024
470329c
Clean up loggables.
mkreuzkam-cap Dec 17, 2024
4a163ae
EW.1019 Add saveAll to account-idm-service
SimoneRadtke-Cap Dec 17, 2024
29534a2
adjust config var usage.
mkreuzkam-cap Dec 17, 2024
8d19ebf
adjust tests (wip)
mkreuzkam-cap Dec 17, 2024
a34c3a8
Fix findMany test in accoundIdm service.
mkreuzkam-cap Dec 18, 2024
1b0627b
Fix tsp sync strategy test.
mkreuzkam-cap Dec 18, 2024
216dfb0
Merge branch 'main' into EW-1019
mkreuzkam-cap Dec 18, 2024
c734169
Add tests for user service and repo.
mkreuzkam-cap Dec 18, 2024
91d5632
Merge branch 'main' into EW-1019
mkreuzkam-cap Dec 18, 2024
54a3d91
EW-1019 Adjust tsp sync service test
SimoneRadtke-Cap Dec 18, 2024
a6e97fa
Fix tests which broke for some reason.
mkreuzkam-cap Dec 18, 2024
b9edb39
Fix another test which broke for no reason.
mkreuzkam-cap Dec 18, 2024
9f3e9f1
Add tests for accounts.
mkreuzkam-cap Dec 19, 2024
e64b935
Fix an oopsie.
mkreuzkam-cap Dec 19, 2024
c58364b
EW-1019 Add test
SimoneRadtke-Cap Dec 19, 2024
905685d
Finish tsp sync migration service test.
mkreuzkam-cap Dec 19, 2024
b49aedb
Merge branch 'main' into EW-1019
mkreuzkam-cap Dec 19, 2024
d534101
Reduce amount of awaits.
mkreuzkam-cap Dec 19, 2024
27c73ea
remove async/await.
mkreuzkam-cap Dec 19, 2024
45c7d41
Remove line.
mkreuzkam-cap Dec 20, 2024
b002a07
Update apps/server/src/modules/account/domain/services/account-db.ser…
mkreuzkam-cap Dec 20, 2024
c6bd5ec
Add return type.
mkreuzkam-cap Dec 20, 2024
a7b728d
fix linter.
mkreuzkam-cap Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
EW-1019 Adjust tsp sync service test
SimoneRadtke-Cap committed Dec 18, 2024
commit 54a3d91f103920661dfd8fd5552ca66b56f1057c
150 changes: 1 addition & 149 deletions apps/server/src/infra/sync/tsp/tsp-sync.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { faker } from '@faker-js/faker';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { AccountService } from '@modules/account';
import { School, SchoolService } from '@modules/school';
import { SystemService, SystemType } from '@modules/system';
import { UserService } from '@modules/user';
import { Test, TestingModule } from '@nestjs/testing';
import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy';
import { federalStateFactory, schoolYearFactory, userDoFactory } from '@shared/testing';
import { accountDoFactory } from '@src/modules/account/testing';
import { federalStateFactory, schoolYearFactory } from '@shared/testing';
import { FederalStateService, SchoolYearService } from '@src/modules/legacy-school';
import { FileStorageType, SchoolProps } from '@src/modules/school/domain';
import { FederalStateEntityMapper, SchoolYearEntityMapper } from '@src/modules/school/repo/mikro-orm/mapper';
@@ -22,8 +19,6 @@ describe(TspSyncService.name, () => {
let schoolService: DeepMocked<SchoolService>;
let federalStateService: DeepMocked<FederalStateService>;
let schoolYearService: DeepMocked<SchoolYearService>;
let userService: DeepMocked<UserService>;
let accountService: DeepMocked<AccountService>;

beforeAll(async () => {
module = await Test.createTestingModule({
@@ -45,14 +40,6 @@ describe(TspSyncService.name, () => {
provide: SchoolYearService,
useValue: createMock<SchoolYearService>(),
},
{
provide: UserService,
useValue: createMock<UserService>(),
},
{
provide: AccountService,
useValue: createMock<AccountService>(),
},
],
}).compile();

@@ -61,8 +48,6 @@ describe(TspSyncService.name, () => {
schoolService = module.get(SchoolService);
federalStateService = module.get(FederalStateService);
schoolYearService = module.get(SchoolYearService);
userService = module.get(UserService);
accountService = module.get(AccountService);
});

afterEach(() => {
@@ -299,137 +284,4 @@ describe(TspSyncService.name, () => {
});
});
});

describe('findUserByTspUid', () => {
describe('when user is found', () => {
const setup = () => {
const tspUid = faker.string.alpha();
const user = userDoFactory.build();

userService.findUsers.mockResolvedValueOnce({ data: [user], total: 1 });

return { tspUid, user };
};

it('should return the user', async () => {
const { tspUid, user } = setup();

const result = await sut.findUserByTspUid(tspUid);

expect(result).toBe(user);
});
});

describe('when user is not found', () => {
const setup = () => {
const tspUid = faker.string.alpha();

userService.findUsers.mockResolvedValueOnce({ data: [], total: 0 });

return { tspUid };
};

it('should return null', async () => {
const { tspUid } = setup();

const result = await sut.findUserByTspUid(tspUid);

expect(result).toBeNull();
});
});
});

describe('findAccountByExternalId', () => {
describe('when account is found', () => {
const setup = () => {
const externalId = faker.string.alpha();
const systemId = faker.string.alpha();

const user = userDoFactory.build();
const account = accountDoFactory.build();

user.id = faker.string.alpha();
user.externalId = externalId;
account.userId = user.id;

userService.findByExternalId.mockResolvedValueOnce(user);
accountService.findByUserId.mockResolvedValueOnce(account);

return { externalId, systemId, account };
};

it('should return the account', async () => {
const { externalId, systemId, account } = setup();

const result = await sut.findAccountByExternalId(externalId, systemId);

expect(result).toBe(account);
});
});

describe('when account is not found', () => {
const setup = () => {
const externalId = faker.string.alpha();
const systemId = faker.string.alpha();

userService.findByExternalId.mockResolvedValueOnce(null);
accountService.findByUserId.mockResolvedValueOnce(null);

return { externalId, systemId };
};

it('should return null', async () => {
const { externalId, systemId } = setup();

const result = await sut.findAccountByExternalId(externalId, systemId);

expect(result).toBeNull();
});
});
});

describe('updateUser', () => {
describe('when user is updated', () => {
const setup = () => {
const oldUid = faker.string.alpha();
const newUid = faker.string.alpha();
const email = faker.internet.email();
const user = userDoFactory.build();

userService.save.mockResolvedValueOnce(user);

return { oldUid, newUid, email, user };
};

it('should return the updated user', async () => {
const { oldUid, newUid, email, user } = setup();

const result = await sut.updateUser(user, email, newUid, oldUid);

expect(result).toBe(user);
});
});
});

describe('updateAccount', () => {
describe('when account is updated', () => {
const setup = () => {
const username = faker.internet.userName();
const systemId = faker.string.alpha();
const account = accountDoFactory.build();

accountService.save.mockResolvedValueOnce(account);

return { username, systemId, account };
};

it('should return the updated account', async () => {
const { username, systemId, account } = setup();

const result = await sut.updateAccount(account, username, systemId);

expect(result).toBe(account);
});
});
});
});
Loading