Skip to content

Commit f72cedd

Browse files
committed
test(deployment): page the team stored secrets across batches against a real database
Part of CON-1213
1 parent 1981d42 commit f72cedd

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

‎apps/api/src/deployment/repositories/deployment-setting/deployment-setting.repository.integration.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,6 +2920,46 @@ describe(DeploymentSettingRepository.name, () => {
29202920
}
29212921
});
29222922

2923+
describe("re-sealing the stored secrets filed in teams", () => {
2924+
it("pages only the live teams' deployments that hold a secret, across batches smaller than the set", async () => {
2925+
const { deploymentSettingRepository, teamSealedIds, passedOverIds } = await setupTeamSecrets();
2926+
const batchSizes: number[] = [];
2927+
const pagedIds: string[] = [];
2928+
2929+
for await (const batch of deploymentSettingRepository.findStoredSecretsOfTeamsIteratively({ batchSize: 1 })) {
2930+
batchSizes.push(batch.length);
2931+
pagedIds.push(...batch.map(row => row.id));
2932+
}
2933+
2934+
expect(batchSizes.every(size => size === 1)).toBe(true);
2935+
expect(new Set(pagedIds).size).toBe(pagedIds.length);
2936+
expect(pagedIds).toEqual(expect.arrayContaining(teamSealedIds));
2937+
expect(pagedIds.filter(id => passedOverIds.includes(id))).toEqual([]);
2938+
});
2939+
2940+
async function setupTeamSecrets() {
2941+
const deploymentSettingRepository = container.resolve(DeploymentSettingRepository);
2942+
const { user, organization: team } = await seedOrganizationWithOwner();
2943+
const { organization: personal } = await seedOrganizationWithOwner({ type: "personal" });
2944+
const { organization: deletedTeam } = await seedOrganizationWithOwner({ deletedAt: new Date() });
2945+
const seedFiledIn = async (organizationId: string, sealedSecrets: string | null) =>
2946+
(await seedDeploymentSetting({ userId: user.id, organizationId, sealedSecrets })).id;
2947+
2948+
const teamSealedIds = [
2949+
await seedFiledIn(team.id, newSealedToken()),
2950+
await seedFiledIn(team.id, newSealedToken()),
2951+
await seedFiledIn(team.id, newSealedToken())
2952+
];
2953+
const passedOverIds = [
2954+
await seedFiledIn(team.id, null),
2955+
await seedFiledIn(personal.id, newSealedToken()),
2956+
await seedFiledIn(deletedTeam.id, newSealedToken())
2957+
];
2958+
2959+
return { deploymentSettingRepository, teamSealedIds, passedOverIds };
2960+
}
2961+
});
2962+
29232963
describe("when a deployment is filed in a team organization", () => {
29242964
it("funds the team deployment from the organization's wallet, never from the member's own", async () => {
29252965
const { deploymentSettingRepository, teamWallet, personalWallet, teamDeployment } = await setupTeamDeployment();

0 commit comments

Comments
 (0)