Skip to content

Commit aa6f46a

Browse files
committed
feat: Added hash tests
1 parent bd3ad86 commit aa6f46a

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

test/hash.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { loadFileAsString, LocalRegistry, VERSIONS_PATH } from './helpers'
2+
import { PACKAGE } from '../src'
3+
4+
const GROUP_NAME = 'manualGroup'
5+
6+
const groupToOnePathOperationIdsMap = {
7+
[GROUP_NAME]: [
8+
'path1-get',
9+
'path1-post',
10+
],
11+
}
12+
13+
describe('Hash test', () => {
14+
describe('Document group hash', () => {
15+
async function publishAndGetHash(packagePath: string): Promise<void> {
16+
const pkg = LocalRegistry.openPackage(packagePath, groupToOnePathOperationIdsMap)
17+
await pkg.publish(pkg.packageId, { packageId: pkg.packageId })
18+
19+
const operationFile = await loadFileAsString(
20+
VERSIONS_PATH,
21+
`${pkg.packageId}/v1`,
22+
`${PACKAGE.OPERATIONS_DIR_NAME}.json`,
23+
)
24+
expect(operationFile).not.toBeNull()
25+
26+
const operationData = JSON.parse(operationFile!)
27+
28+
expect(operationData.operations.length).toBe(2)
29+
expect(operationData.operations[0]).not.toEqual(operationData.operations[1])
30+
}
31+
32+
test('should be different hashes for each operation', async () => {
33+
await publishAndGetHash('hash/different-hashes-for-each-operation')
34+
})
35+
36+
test('should be different hashes for each pathitems operation', async () => {
37+
await publishAndGetHash('hash/different-hashes-for-each-pathitems-operation')
38+
})
39+
})
40+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: test
4+
version: 0.1.0
5+
paths:
6+
/path1:
7+
get:
8+
responses:
9+
'200':
10+
description: response description main
11+
post:
12+
responses:
13+
'200':
14+
description: response description main
15+
16+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"packageId": "55",
3+
"apiType": "rest",
4+
"version": "v1",
5+
"files": [
6+
{
7+
"fileId": "1.yaml",
8+
"publish": true,
9+
"labels": [],
10+
"commitId": "6c778b1f44200bd19944a6a8eac10a4e5a21a3cd"
11+
}
12+
]
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: test
4+
version: 0.1.0
5+
paths:
6+
/path1:
7+
$ref: '#/components/pathItems/pathItem1'
8+
components:
9+
pathItems:
10+
pathItem1:
11+
get:
12+
responses:
13+
'200':
14+
description: response description main
15+
post:
16+
responses:
17+
'200':
18+
description: response description main
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"packageId": "55",
3+
"apiType": "rest",
4+
"version": "v1",
5+
"files": [
6+
{
7+
"fileId": "1.yaml",
8+
"publish": true,
9+
"labels": [],
10+
"commitId": "6c778b1f44200bd19944a6a8eac10a4e5a21a3cd"
11+
}
12+
]
13+
}

0 commit comments

Comments
 (0)