This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RAINCATCH-1388] Filestore tests (#180)
* Start refactoring for tests * Add some tests for filestore * Add tests for writeStreamToFile * Finish tests for fileService * Lower coverage reqs * Rename storage class to match filename * Add string type for createTemporaryStorageFolder * Add first tests for gridfs storage * Add tests for gridfs * Update jsdocs * Update package version to pre-release one * update dependencies to match hoisted versions * Fix hanging test
- Loading branch information
1 parent
e3618a2
commit 6cbed01
Showing
10 changed files
with
236 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as Promise from 'bluebird'; | ||
import { expect } from 'chai'; | ||
import * as chai from 'chai'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
import { readFileSync } from 'fs'; | ||
import * as mongo from 'mongodb'; | ||
import { MongoClient } from 'mongodb'; | ||
import * as path from 'path'; | ||
import { FileMetadata } from '../../src/file-api/FileMetadata'; | ||
import { GridFsStorage } from '../../src/impl/GridFsStorage'; | ||
|
||
const connectAsync = Promise.promisify<mongo.Db, string>(MongoClient.connect); | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
function readStream(stream: NodeJS.ReadableStream): Promise<string> { | ||
let data = ''; | ||
stream.setEncoding('utf8'); | ||
stream.on('data', chunk => data += chunk); | ||
return new Promise(resolve => stream.on('end', () => resolve(data))); | ||
} | ||
|
||
describe('GridFsStorage', function() { | ||
const mongoUrl = 'mongodb://127.0.0.1:27017/testdb'; | ||
const dbFactory = () => connectAsync(mongoUrl); | ||
let db: mongo.Db; | ||
const metadata: FileMetadata = { | ||
id: 'test-file' | ||
}; | ||
const fileLocation = path.resolve(__dirname, '../fixtures/test.txt'); | ||
const fileContents = readFileSync(fileLocation, { | ||
encoding: 'utf8' | ||
}); | ||
|
||
before(function() { | ||
return dbFactory().then(database => db = database); | ||
}); | ||
after(function() { | ||
db.close(); | ||
}); | ||
|
||
describe('constructor', function() { | ||
it('should accept a mongodb connection', function() { | ||
const storage = new GridFsStorage(db); | ||
return expect(storage.gridFileSystem).to.exist && | ||
expect(storage.getFileSystem()).to.eventually.be.fulfilled; | ||
}); | ||
}); | ||
|
||
it('should write and read back a file from storage', function() { | ||
const storage = new GridFsStorage(db); | ||
const write = storage.writeFile(metadata, fileLocation); | ||
const read = write | ||
.then(() => storage.readFile(metadata.id)) | ||
.then(readStream); | ||
return expect(write).to.eventually.be.fulfilled && | ||
expect(read).to.eventually.equal(fileContents); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
--compilers ts:ts-node/register | ||
--require source-map-support/register | ||
test/**.ts | ||
test/**/*.ts |
Oops, something went wrong.