Commit abe72eee authored by Mike Lynch's avatar Mike Lynch
Browse files

Conversion to async/await style is done, all tests passing

parent e63f6781
......@@ -56,7 +56,7 @@ export class FilesApp extends BaseApp implements IApp {
async find(id: string): Promise<IObject|null> {
await this.index();
let m = this._index.filter(o => { o.id == id});
let m = this._index.filter(o => o.id == id);
if( m ) {
return m[0];
} else {
......@@ -69,9 +69,9 @@ export class FilesApp extends BaseApp implements IApp {
async create(id: string): Promise<IObject|null> {
await this.index();
let matches = this._index.filter(o => { return o.id == id } );
let matches = this._index.filter(o => o.id == id );
if( matches.length ) {
throw new Error("FilesObject with id " + id + " already exists");
throw Error("FilesObject with id " + id + " already exists");
} else {
let fopath = path.join(this.uri, id);
let fo = new FilesObject(this, id, id);
......
......@@ -10,47 +10,40 @@ import { FilesAppFixture } from './FilesApp.fixtures';
const FIXTURE_ID = "fileapp1";
const FIXTURE_DIR = "test/fixtures/fileapp1"
describe.skip('FilesObject', function() {
describe('FilesObject', function() {
let fixture = new FilesAppFixture(FIXTURE_ID, FIXTURE_DIR);
beforeEach((done) => fixture.buildup(done));
afterEach((done) => fixture.teardown(done));
// afterEach((done) => fixture.teardown(done));
it('can create a new FilesObject', function(done) {
it('can create a new FilesObject', async () => {
const fa = new FilesApp(FIXTURE_ID, FIXTURE_DIR);
const oid = 'object1';
fa.create(oid, function(fo) {
expect(fo).to.have.property('id').to.equal(oid);
expect(fo).to.have.property('app').to.equal(fa);
expect(fo).to.have.property('path').to.equal(oid);
done();
});
const fo = await fa.create(oid);
expect(fo).to.have.property('id').to.equal(oid);
expect(fo).to.have.property('app').to.equal(fa);
expect(fo).to.have.property('path').to.equal(oid);
});
it('can find a FilesObject in the index', function(done) {
it('can find a FilesObject in the index', async () => {
const fa = new FilesApp(FIXTURE_ID, FIXTURE_DIR);
const oid = 'object1';
fa.create(oid, function(fo) {
fa.find(oid, function(fo2) {
expect(fo).to.have.property('id').to.equal(oid);
done();
});
});
const fo1 = await fa.create(oid);
const fo2 = await fa.find(oid);
expect(fo2).to.have.property('id').to.equal(oid);
});
it("will not create two FilesObjects with the same id", function(done) {
const fa = new FilesApp(FIXTURE_ID, FIXTURE_DIR);
it("will not create two FilesObjects with the same id", async function() {
const oid = 'object1';
done();
expect(() => {
fa.create(oid, function(fo) {
fa.create(oid, function(fo2) {
console.log("Shouldn't get here");
});
});
}).to.throw();
done();
try {
const fa = new FilesApp(FIXTURE_ID, FIXTURE_DIR);
const fo1 = await fa.create(oid);
const fo2 = await fa.create(oid);
} catch ( err ) {
expect(err).to.be.a('Error');
expect(err.message).to.contain('already exists');
}
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment