-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathbuild-remote-path.spec.ts
More file actions
42 lines (35 loc) · 1.24 KB
/
build-remote-path.spec.ts
File metadata and controls
42 lines (35 loc) · 1.24 KB
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
import { BaseRecord, UploadedFile } from 'adminjs'
import { expect } from 'chai'
import sinon, { createStubInstance } from 'sinon'
import { buildRemotePath } from './build-remote-path.js'
describe('buildPath', () => {
let recordStub: BaseRecord
const recordId = '1'
const File: UploadedFile = {
name: 'some-name.pdf',
path: '/some-path.pdf',
size: 111,
type: 'txt',
}
after(() => {
sinon.restore()
})
before(() => {
recordStub = createStubInstance(BaseRecord, {
id: sinon.stub<any, string>().returns(recordId),
isValid: sinon.stub<any, boolean>().returns(true),
update: sinon.stub<any, Promise<BaseRecord>>().returnsThis(),
})
recordStub.params = {}
})
it('returns default path when no custom function is given', async () => {
expect(await buildRemotePath(recordStub, File)).to.equal(`${recordId}/${File.name}`)
})
it('returns custom path when function is given', async () => {
const newPath = '1/1/filename'
const fnStub = sinon.stub<[BaseRecord, string, UploadedFile], string>().returns(newPath)
const path = await buildRemotePath(recordStub, File, fnStub)
expect(path).to.equal(newPath)
expect(fnStub).to.have.been.calledWith(recordStub, File.name, File)
})
})