|
8 | 8 | normalFullTerms, |
9 | 9 | normalContract, |
10 | 10 | normalNoTerms, |
| 11 | + contractWithDefaults, |
11 | 12 | } from './helpers/contract.helpers'; |
12 | 13 | import { VC } from '@learncard/types'; |
13 | 14 |
|
@@ -96,6 +97,53 @@ describe('ConsentFlow E2E Tests', () => { |
96 | 97 | expect(error).toBeDefined(); |
97 | 98 | } |
98 | 99 | }); |
| 100 | + |
| 101 | + it('should allow creating and retrieving a contract with defaultEnabled fields', async () => { |
| 102 | + const contractName = `Default Enabled Contract ${Date.now()}`; |
| 103 | + const contractUri = await a.invoke.createContract({ |
| 104 | + contract: contractWithDefaults, |
| 105 | + name: contractName, |
| 106 | + description: 'A contract for testing defaultEnabled fields', |
| 107 | + }); |
| 108 | + |
| 109 | + expect(contractUri).toBeDefined(); |
| 110 | + expect(typeof contractUri).toBe('string'); |
| 111 | + |
| 112 | + // Retrieve the contract and verify defaultEnabled fields are preserved |
| 113 | + const contract = await a.invoke.getContract(contractUri); |
| 114 | + |
| 115 | + expect(contract).toBeDefined(); |
| 116 | + expect(contract.name).toBe(contractName); |
| 117 | + expect(contract.description).toBe('A contract for testing defaultEnabled fields'); |
| 118 | + |
| 119 | + // Verify read section defaultEnabled fields |
| 120 | + expect(contract.contract.read.personal.name?.defaultEnabled).toBe(true); |
| 121 | + expect(contract.contract.read.personal.email?.defaultEnabled).toBe(false); |
| 122 | + expect(contract.contract.read.personal.phone?.defaultEnabled).toBe(true); |
| 123 | + expect(contract.contract.read.credentials.categories.Achievement?.defaultEnabled).toBe( |
| 124 | + true |
| 125 | + ); |
| 126 | + expect(contract.contract.read.credentials.categories.ID?.defaultEnabled).toBe(false); |
| 127 | + expect(contract.contract.read.credentials.categories.Certificate?.defaultEnabled).toBe( |
| 128 | + false |
| 129 | + ); |
| 130 | + |
| 131 | + // Verify write section defaultEnabled fields |
| 132 | + expect(contract.contract.write.personal.name?.defaultEnabled).toBe(true); |
| 133 | + expect(contract.contract.write.personal.email?.defaultEnabled).toBe(false); |
| 134 | + expect(contract.contract.write.credentials.categories.Achievement?.defaultEnabled).toBe( |
| 135 | + false |
| 136 | + ); |
| 137 | + expect(contract.contract.write.credentials.categories.Badge?.defaultEnabled).toBe(true); |
| 138 | + |
| 139 | + // Verify required fields are still preserved alongside defaultEnabled |
| 140 | + expect(contract.contract.read.personal.name?.required).toBe(false); |
| 141 | + expect(contract.contract.read.personal.email?.required).toBe(true); |
| 142 | + expect(contract.contract.read.credentials.categories.Achievement?.required).toBe(false); |
| 143 | + expect(contract.contract.read.credentials.categories.Certificate?.required).toBe(true); |
| 144 | + expect(contract.contract.write.credentials.categories.Achievement?.required).toBe(true); |
| 145 | + expect(contract.contract.write.credentials.categories.Badge?.required).toBe(false); |
| 146 | + }); |
99 | 147 | }); |
100 | 148 |
|
101 | 149 | describe('Contract Consent Flow', () => { |
@@ -471,6 +519,31 @@ describe('ConsentFlow E2E Tests', () => { |
471 | 519 | const hasWriteAction = transactions.records.some(tx => tx.action === 'write'); |
472 | 520 | expect(hasWriteAction).toBe(true); |
473 | 521 | }); |
| 522 | + |
| 523 | + it('should NOT auto-issue boosts when write permission is denied in consent terms', async () => { |
| 524 | + // Create a contract with autoboost for Achievement category |
| 525 | + const contractUri = await a.invoke.createContract({ |
| 526 | + contract: normalContract, // Allows Achievement category |
| 527 | + name: 'Security Test Contract', |
| 528 | + description: 'Testing autoboost permission enforcement', |
| 529 | + autoboosts: [{ boostUri, signingAuthority }], // Use existing boostUri and signingAuthority |
| 530 | + }); |
| 531 | + |
| 532 | + // User B consents but DENIES write permission for Achievement category |
| 533 | + const termsUri = await b.invoke.consentToContract(contractUri, { |
| 534 | + terms: normalNoTerms, // This denies ALL write permissions: Achievement: false, ID: false |
| 535 | + }); |
| 536 | + |
| 537 | + expect(termsUri).toBeDefined(); |
| 538 | + |
| 539 | + // Wait a moment for any autoboost processing |
| 540 | + await new Promise(resolve => setTimeout(resolve, 1000)); |
| 541 | + |
| 542 | + // Check if any credentials were issued (there should be NONE) |
| 543 | + const credentials = await b.invoke.getCredentialsForContract(termsUri); |
| 544 | + |
| 545 | + expect(credentials.records).toHaveLength(0); |
| 546 | + }); |
474 | 547 | }); |
475 | 548 |
|
476 | 549 | describe('Auto-Boosts with Denied Writers', () => { |
|
0 commit comments