Skip to content

chore(#368): enforce unit tests typing#367

Open
jonathanbataire wants to merge 17 commits into
mainfrom
unitest-typing
Open

chore(#368): enforce unit tests typing#367
jonathanbataire wants to merge 17 commits into
mainfrom
unitest-typing

Conversation

@jonathanbataire

@jonathanbataire jonathanbataire commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

fixes #368

@jonathanbataire
jonathanbataire requested review from freddieptf and kennsippell and removed request for freddieptf and kennsippell June 25, 2026 12:39
@jonathanbataire
jonathanbataire marked this pull request as draft June 25, 2026 12:53
@jonathanbataire
jonathanbataire marked this pull request as ready for review June 25, 2026 18:25
@jonathanbataire jonathanbataire changed the title fix: enable unit tests typing fix(#368): enable unit tests typing Jun 26, 2026
@jonathanbataire jonathanbataire changed the title fix(#368): enable unit tests typing fix(#368): enforce unit tests typing Jun 29, 2026
decodeTokenStub.returns(session);

await MoveLib.scheduleJob(
await (MoveLib as any).scheduleJob(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this one chief, do we really need this when calling static funcs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

@jonathanbataire jonathanbataire Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im mainly just adding types to whats existing without fiddling with existing logic
the any changes nothing compared to what was there
how can we handle this better?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case i find it odd that a call needs some type, i assumed await MoveLib.scheduleJob(... would just work

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

movelib.schedulejob takes only 2 args this test is passing 5
hence the casting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that seems wrong and i don't think these integration tests run at all. I think it can be handled in another PR. Could you create another issue for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread test/lib/authentication.spec.ts Outdated
it('invalid session cannot be decoded for cookie', () => {
const session = mockChtSession();
delete session.username;
delete (session as any).username;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be ChtSession instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the properties username and password of CHTSession are readonly
meaning they cant be deleted
this test is deleting them
in order for that to happen we need to cast it to any

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, what about initializing an invalid cht session to avoid the deletion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have improved this

Comment thread test/lib/disable-users.spec.ts Outdated
place: { _id: PLACE_ID }
}]);
const actual = await DisableUsers.disableUsersAt([PLACE_ID], cht);
const actual = await DisableUsers.disableUsersAt([PLACE_ID], cht as unknown as ChtApi);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cht as unknown as ChtApi is this some ts quirk you're working around?

Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is mainly how these tests were written originally
no types meaning you could write anything that doesn't fit the the argument type and things work
cht is not type CHTApi the double type casting as unkown as ChtApi is a way to force cht be type ChtApi even though it doesnt fit the original type
these mistakes were caused by lack of type enforcing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made improvements to CHTApi mock logic to reduce this double casting

Comment thread test/lib/sso-login.spec.ts Outdated
const attackerCall = stub.getCalls().find(c => new URL(c.args[0].url as string).host === 'idp.example.com.attacker.com');
expect(attackerCall, 'attacker host was visited').to.exist;
expect(attackerCall!.args[0].headers.Authorization).to.be.undefined;
expect((attackerCall!.args[0].headers as any)?.Authorization).to.be.undefined;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there some http.Headers type you can use here?

@freddieptf freddieptf changed the title fix(#368): enforce unit tests typing chore(#368): enforce unit tests typing Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable typscript typing for tests

2 participants