2023-12-14 12:50:51 +03:00
|
|
|
import type { INestApplication } from '@nestjs/common';
|
|
|
|
import request from 'supertest';
|
|
|
|
|
|
|
|
import { gql } from './common';
|
|
|
|
|
|
|
|
export async function listBlobs(
|
|
|
|
app: INestApplication,
|
|
|
|
token: string,
|
|
|
|
workspaceId: string
|
|
|
|
): Promise<string[]> {
|
|
|
|
const res = await request(app.getHttpServer())
|
|
|
|
.post(gql)
|
|
|
|
.auth(token, { type: 'bearer' })
|
|
|
|
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
|
|
|
|
.send({
|
|
|
|
query: `
|
|
|
|
query {
|
|
|
|
listBlobs(workspaceId: "${workspaceId}")
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
.expect(200);
|
|
|
|
return res.body.data.listBlobs;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getWorkspaceBlobsSize(
|
|
|
|
app: INestApplication,
|
|
|
|
token: string,
|
|
|
|
workspaceId: string
|
|
|
|
): Promise<number> {
|
|
|
|
const res = await request(app.getHttpServer())
|
|
|
|
.post(gql)
|
|
|
|
.auth(token, { type: 'bearer' })
|
|
|
|
.send({
|
|
|
|
query: `
|
|
|
|
query {
|
|
|
|
workspace(id: "${workspaceId}") {
|
|
|
|
blobsSize
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
.expect(200);
|
|
|
|
return res.body.data.workspace.blobsSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function collectAllBlobSizes(
|
|
|
|
app: INestApplication,
|
|
|
|
token: string
|
|
|
|
): Promise<number> {
|
|
|
|
const res = await request(app.getHttpServer())
|
|
|
|
.post(gql)
|
|
|
|
.auth(token, { type: 'bearer' })
|
|
|
|
.send({
|
|
|
|
query: `
|
|
|
|
query {
|
2024-12-10 13:48:27 +03:00
|
|
|
currentUser {
|
|
|
|
quotaUsage {
|
|
|
|
storageQuota
|
|
|
|
}
|
2023-12-14 12:50:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
.expect(200);
|
2024-12-10 13:48:27 +03:00
|
|
|
return res.body.data.currentUser.quotaUsage.storageQuota;
|
2023-12-14 12:50:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function setBlob(
|
|
|
|
app: INestApplication,
|
|
|
|
token: string,
|
|
|
|
workspaceId: string,
|
|
|
|
buffer: Buffer
|
|
|
|
): Promise<string> {
|
|
|
|
const res = await request(app.getHttpServer())
|
|
|
|
.post(gql)
|
|
|
|
.auth(token, { type: 'bearer' })
|
|
|
|
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
|
|
|
|
.field(
|
|
|
|
'operations',
|
|
|
|
JSON.stringify({
|
|
|
|
name: 'setBlob',
|
|
|
|
query: `mutation setBlob($blob: Upload!) {
|
|
|
|
setBlob(workspaceId: "${workspaceId}", blob: $blob)
|
|
|
|
}`,
|
|
|
|
variables: { blob: null },
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.field('map', JSON.stringify({ '0': ['variables.blob'] }))
|
2024-01-03 13:56:54 +03:00
|
|
|
.attach(
|
|
|
|
'0',
|
|
|
|
buffer,
|
|
|
|
`blob-${Math.random().toString(16).substring(2, 10)}.data`
|
|
|
|
)
|
2023-12-14 12:50:51 +03:00
|
|
|
.expect(200);
|
|
|
|
return res.body.data.setBlob;
|
|
|
|
}
|