Skip to content

Commit 23505f1

Browse files
committed
fix: improve test
1 parent a404dbf commit 23505f1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

test/e2e/sdk/publicUrl/src/main.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { Actor, log } from 'apify';
22

3+
// Also needs to be changed in test.mjs
34
const PUBLIC_RECORD_KEY = 'public-record-key';
5+
const PUBLIC_DATA = { exposedData: 'test' };
46

57
await Actor.init();
68

7-
await Actor.setValue(PUBLIC_RECORD_KEY, JSON.stringify({ exposedData: 'test' }), { contentType: `application/json` });
9+
await Actor.setValue(PUBLIC_RECORD_KEY, JSON.stringify(PUBLIC_DATA), { contentType: `application/json` });
810

911
const defaultKeyValueStore = await Actor.openKeyValueStore();
1012
const publicUrl = defaultKeyValueStore.getPublicUrl(PUBLIC_RECORD_KEY);
1113

14+
// Here we store the url itself
15+
await Actor.setValue('urlToPublicData', publicUrl);
16+
1217
log.info('Generated public url', { publicUrl });
1318

1419
await Actor.pushData({ publicUrl });

test/e2e/sdk/publicUrl/test.mjs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import assert from 'node:assert/strict';
22

3-
import { createHmacSignature } from '@apify/utilities';
4-
import { ApifyClient, Dataset } from 'apify';
3+
import { ApifyClient } from 'apify';
54

65
// Also needs to be changed in main.mjs
7-
const PUBLIC_RECORD_KEY = 'public-record-key';
6+
const PUBLIC_DATA = { exposedData: 'test' };
87

98
const client = new ApifyClient({
109
token: process.env.APIFY_TOKEN,
@@ -15,8 +14,7 @@ const actor = client.actor(process.argv[2]);
1514
const run = await actor.call({}, { waitSecs: 15 });
1615
assert.equal(run.exitCode, 0);
1716

18-
const keyValueStore = await client.keyValueStore(run.defaultKeyValueStoreId).get();
17+
const publicUrl = await client.keyValueStore(run.defaultKeyValueStoreId).getRecord('urlToPublicData');
18+
const data = await fetch(publicUrl.value).then((res) => res.json());
1919

20-
const dataset = await Dataset.open(run.defaultDatasetId, { storageClient: client });
21-
const data = await dataset.getData();
22-
assert.deepEqual(data.items, [{ publicUrl: `https://api.apify.com/v2/key-value-stores/${keyValueStore.id}/records/${PUBLIC_RECORD_KEY}?signature=${createHmacSignature(keyValueStore.urlSigningSecretKey, PUBLIC_RECORD_KEY)}` }]);
20+
assert.deepEqual(data, PUBLIC_DATA);

0 commit comments

Comments
 (0)