-
Notifications
You must be signed in to change notification settings - Fork 1
/
deep-files-sync.test.js
88 lines (70 loc) · 3.15 KB
/
deep-files-sync.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//import { DeepClient, parseJwt } from "@deep-foundation/deeplinks/imports/client.js";
test('Test deep file sync', async () => {
// Импортируйте необходимые модули
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
const { expect } = require('@jest/globals');
// Определите путь к вашей утилите
const utilityPath = './index.js';
// Определите параметры для вашей утилиты
const spaceId = '1008';
const folderPath = './folder';
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWFsbG93ZWQtcm9sZXMiOlsibGluayJdLCJ4LWhhc3VyYS1kZWZhdWx0LXJvbGUiOiJsaW5rIiwieC1oYXN1cmEtdXNlci1pZCI6IjEwMDgifSwiaWF0IjoxNzA3NDg1MzMzfQ.1OsqDtt_wMbhnzggNeQGlo8M_xjtHW7VZoggYsP8j-A';
let urn = 'https://3006-deepfoundation-dev-usj38r207un.ws-eu108.gitpod.io';
let ssl;
const url_protocol = urn.match(/^(http:|https:)/)[0];
if (url_protocol === "https:") {
ssl = true;
} else if (url_protocol === "http:") {
ssl = false;
} else {
throw new Error(`Unsupported protocol: ${url.protocol}`);
}
if (!urn.endsWith("/gql")) {
urn += "/gql";
}
urn = urn.replace(/^https:\/\//, "");
urn.replace(/^http:\/\//, "");
const GQL_URN = process.env.GQL_URN || urn
const GQL_SSL = process.env.GQL_SSL || ssl;
const makeDeepClient = token => {
if (!token) throw new Error("No token provided")
const decoded = parseJwt(token)
const linkId = decoded.userId
const apolloClient = generateApolloClient({
path: GQL_URN,
ssl: !!+GQL_SSL,
token
})
const deepClient = new DeepClient({ apolloClient, linkId, token })
//console.log(deepClient);
return deepClient
}
deep = makeDeepClient(token);
// Запустите вашу утилиту
exec(`node ${utilityPath} --url ${url} --space-id ${spaceId} --folder-path ${folderPath} --token ${token}`, async (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
// Создайте тестовый файл с задержкой
});
setTimeout(() => {
const testFileName = 'testFile.txt';
const testFilePath = path.join(folderPath, testFileName);
fs.writeFileSync(testFilePath, 'This is a test file.');
const { data } = deep.select({
type_id: 3,
string: { value: { _eq: testFileName } }
});
const fileWasAdded = data.length > 0;
// Используйте Jest для проверки результата
expect(fileWasAdded).toBe(true);
}, 3000); // Задержка в 5 секунд
// Проверьте, был ли файл добавлен в базу данных
});