Skip to content

Commit 9a3ec2f

Browse files
test: update userRepository methods to use admitUser instead of upsert
1 parent 811746c commit 9a3ec2f

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

test/unit/services/payments-service.spec.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe('PaymentsService', () => {
5656

5757
userRepository = {
5858
upsert: sandbox.stub().resolves(),
59+
admitUser: sandbox.stub().resolves(),
5960
findByPubkey: sandbox.stub(),
6061
}
6162

@@ -310,7 +311,7 @@ describe('PaymentsService', () => {
310311
amountPaid: 2n,
311312
}))
312313

313-
expect(userRepository.upsert).to.have.been.calledOnce
314+
expect(userRepository.admitUser).to.have.been.calledOnce
314315
expect(mockTrx.commit).to.have.been.calledOnce
315316
})
316317

@@ -323,7 +324,7 @@ describe('PaymentsService', () => {
323324
amountPaid: 1n,
324325
}))
325326

326-
expect(userRepository.upsert).to.have.been.calledOnce
327+
expect(userRepository.admitUser).to.have.been.calledOnce
327328
})
328329

329330
it('does not convert MSATS (uses amount directly)', async () => {
@@ -334,7 +335,7 @@ describe('PaymentsService', () => {
334335
amountPaid: 2000n,
335336
}))
336337

337-
expect(userRepository.upsert).to.have.been.calledOnce
338+
expect(userRepository.admitUser).to.have.been.calledOnce
338339
})
339340

340341
it('admits the user when the paid amount meets the admission fee', async () => {
@@ -346,9 +347,10 @@ describe('PaymentsService', () => {
346347
amountPaid: 5000n,
347348
}))
348349

349-
expect(userRepository.upsert).to.have.been.calledOnce
350-
const [upsertArg] = userRepository.upsert.firstCall.args
351-
expect(upsertArg).to.include({ isAdmitted: true, pubkey: 'admittedpubkey' })
350+
expect(userRepository.admitUser).to.have.been.calledOnce
351+
const [pubkeyArg, admittedAtArg] = userRepository.admitUser.firstCall.args
352+
expect(pubkeyArg).to.equal('admittedpubkey')
353+
expect(admittedAtArg).to.be.instanceOf(Date)
352354
expect(mockTrx.commit).to.have.been.calledOnce
353355
})
354356

@@ -360,7 +362,7 @@ describe('PaymentsService', () => {
360362
amountPaid: 500n,
361363
}))
362364

363-
expect(userRepository.upsert).not.to.have.been.called
365+
expect(userRepository.admitUser).not.to.have.been.called
364366
expect(mockTrx.commit).to.have.been.calledOnce
365367
})
366368

@@ -369,7 +371,7 @@ describe('PaymentsService', () => {
369371

370372
await service.confirmInvoice(makeCompletedInvoice())
371373

372-
expect(userRepository.upsert).not.to.have.been.called
374+
expect(userRepository.admitUser).not.to.have.been.called
373375
})
374376

375377
it('falls back to an empty admission array when feeSchedules is missing', async () => {
@@ -378,7 +380,7 @@ describe('PaymentsService', () => {
378380

379381
await service.confirmInvoice(makeCompletedInvoice())
380382

381-
expect(userRepository.upsert).not.to.have.been.called
383+
expect(userRepository.admitUser).not.to.have.been.called
382384
})
383385

384386
it('ignores disabled fee schedules when computing the admission amount', async () => {
@@ -390,7 +392,7 @@ describe('PaymentsService', () => {
390392
}))
391393

392394
// disabled → admissionFeeAmount = 0 → condition false → user not admitted
393-
expect(userRepository.upsert).not.to.have.been.called
395+
expect(userRepository.admitUser).not.to.have.been.called
394396
})
395397

396398
it('skips the fee for whitelisted pubkeys', async () => {
@@ -405,7 +407,7 @@ describe('PaymentsService', () => {
405407
}))
406408

407409
// pubkey starts with 'whitelisted' → isApplicableFee = false → admissionFeeAmount = 0 → not admitted
408-
expect(userRepository.upsert).not.to.have.been.called
410+
expect(userRepository.admitUser).not.to.have.been.called
409411
})
410412

411413
it('rolls back the transaction and re-throws on error', async () => {

0 commit comments

Comments
 (0)