Skip to content

Commit 63a5e14

Browse files
Add test for asset upload with bundles in hash directories
- Implemented a new test case for the `/upload-assets` endpoint to verify that bundles are correctly placed in their own hash directories rather than the targetBundles directory. - Ensured that the test checks for the existence of the bundle in the appropriate directory and confirms that the target bundle directory remains empty, enhancing coverage for asset upload scenarios.
1 parent 2d6cc9b commit 63a5e14

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

react_on_rails_pro/packages/node-renderer/tests/worker.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,4 +672,50 @@ describe('worker', () => {
672672
// Verify the original content is preserved (62 bytes from bundle.js, not 84 from secondary-bundle.js)
673673
expect(secondBundleSize).toBe(62); // Size of getFixtureBundle(), not getFixtureSecondaryBundle()
674674
});
675+
676+
test('post /upload-assets with bundles placed in their own hash directories, not targetBundles directories', async () => {
677+
const bundleHash = 'actual-bundle-hash';
678+
const targetBundleHash = 'target-bundle-hash'; // Different from actual bundle hash
679+
680+
const app = worker({
681+
bundlePath: bundlePathForTest(),
682+
password: 'my_password',
683+
});
684+
685+
const form = formAutoContent({
686+
gemVersion,
687+
protocolVersion,
688+
password: 'my_password',
689+
targetBundles: [targetBundleHash], // This should NOT affect where the bundle is placed
690+
[`bundle_${bundleHash}`]: createReadStream(getFixtureBundle()), // Bundle with its own hash
691+
});
692+
693+
const res = await app.inject().post(`/upload-assets`).payload(form.payload).headers(form.headers).end();
694+
expect(res.statusCode).toBe(200);
695+
696+
// Verify the bundle was placed in its OWN hash directory, not the targetBundles directory
697+
const actualBundleDir = path.join(bundlePathForTest(), bundleHash);
698+
const targetBundleDir = path.join(bundlePathForTest(), targetBundleHash);
699+
700+
// Bundle should exist in its own hash directory
701+
expect(fs.existsSync(actualBundleDir)).toBe(true);
702+
const bundleFilePath = path.join(actualBundleDir, `${bundleHash}.js`);
703+
expect(fs.existsSync(bundleFilePath)).toBe(true);
704+
705+
// Target bundle directory should also exist (created for assets)
706+
expect(fs.existsSync(targetBundleDir)).toBe(true);
707+
708+
// But the bundle file should NOT be in the target bundle directory
709+
const targetBundleFilePath = path.join(targetBundleDir, `${bundleHash}.js`);
710+
expect(fs.existsSync(targetBundleFilePath)).toBe(false);
711+
712+
// Verify the bundle is in the correct location with correct name
713+
const files = fs.readdirSync(actualBundleDir);
714+
expect(files).toHaveLength(1);
715+
expect(files[0]).toBe(`${bundleHash}.js`);
716+
717+
// Verify the target bundle directory is empty (no assets uploaded)
718+
const targetFiles = fs.readdirSync(targetBundleDir);
719+
expect(targetFiles).toHaveLength(0);
720+
});
675721
});

0 commit comments

Comments
 (0)