Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions models.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"config.*.json"
],
"relations": {
"package": {
"type": "hasOne",
"model": "PackageDefinition",
"foreignKey": "componentName"
},
"models": {
"type": "hasMany",
"model": "ModelDefinition",
Expand Down
8 changes: 6 additions & 2 deletions models/workspace-entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ WorkspaceEntity.allFromCache = function(cache) {
.map(this.getFromCache.bind(this, cache));
}

WorkspaceEntity.getPath = function(app, obj) {
WorkspaceEntity.getPath = function(componentName, obj) {
if(obj.configFile) return obj.configFile;
return path.join(app, this.settings.defaultConfigFile);
return path.join(componentName, this.settings.defaultConfigFile);
}

WorkspaceEntity.getDir = function(componentName, obj) {
return path.dirname(WorkspaceEntity.getPath(componentName, obj));
}

WorkspaceEntity.getConfigFile = function(componentName, obj) {
Expand Down
6 changes: 1 addition & 5 deletions models/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,13 @@ Workspace.addComponent = function(options, cb) {
steps.push(function(cb) {
fs.exists(fileTemplatesDir, function(exists) {
if(exists) {
steps.push(copyTemplateFiles);
cb();
ncp(fileTemplatesDir, dest, cb);
} else {
cb();
}
});
});

function copyTemplateFiles(cb) {
ncp(fileTemplatesDir, dest, cb);
}
function setComponentName(obj) {
if(Array.isArray(obj)) {
obj.forEach(function(item) {
Expand Down
2 changes: 1 addition & 1 deletion templates/api-server/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ template.package = {
"optionalDependencies": {
"loopback-explorer": "^1.1.0"
}
};
};
2 changes: 1 addition & 1 deletion templates/rest/template/boot/authentication.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var rest = require('../rest');

// enable authentication
server.enableAuth();
rest.enableAuth();
2 changes: 1 addition & 1 deletion templates/rest/template/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ var server = module.exports = loopback();
boot(server, __dirname);

// middleware
server.use(loopback.rest());
server.use(loopback.rest());
2 changes: 1 addition & 1 deletion templates/server/template/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ app.start = function() {
// start the server if `$ node server.js`
if (require.main === module) {
app.start();
}
}
8 changes: 8 additions & 0 deletions test/component-definition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var async = require('async');
var app = require('../app');
var ComponentDefinition = app.models.ComponentDefinition;
var ConfigFile = app.models.ConfigFile;

describe('ComponentDefinition', function() {

});
4 changes: 4 additions & 0 deletions test/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ expectFileExists = function (file) {
assert(fs.existsSync(file), file + ' does not exist');
}

getPath = function(relativePath) {
return ConfigFile.toAbsolutePath(relativePath);
}

expectValueInJSONFile = function(file, propertyPath, val) {
var contents = fs.readFileSync(file, 'utf8');
var obj = JSON.parse(contents);
Expand Down
26 changes: 25 additions & 1 deletion test/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var app = require('../app');
var TestDataBuilder = require('loopback-testing').TestDataBuilder;
var Workspace = app.models.Workspace;
var ConfigFile = app.models.ConfigFile;
var ComponentDefinition = app.models.ComponentDefinition;

describe('Workspace', function() {
describe('Workspace.getAvailableTemplates(callback)', function() {
Expand All @@ -16,6 +17,19 @@ describe('Workspace', function() {
});
});

describe('Workspace.addComponent(options, cb)', function () {
beforeEach(givenEmptySandbox);
beforeEach(function(done) {
Workspace.addComponent({
template: 'rest'
}, done);
});
it('should add the static component files', function () {
expectFileExists(getPath('rest/rest.js'));
expectFileExists(getPath('rest/boot/authentication.js'));
});
});

describe('Workspace.createFromTemplate(templateName, callback)', function() {
beforeEach(givenBasicWorkspace);
beforeEach(findAllEntities);
Expand Down Expand Up @@ -46,13 +60,23 @@ describe('Workspace', function() {
expect(dataSourceNames).to.contain('mail');
expect(dataSourceNames).to.contain('db');
});

it('should create a runnable set of components', function (done) {
ComponentDefinition.findOne({
where: {
name: '.'
}
}, function(err, component) {
if(err) return done(err);
done();
});
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not assert anything, it should be removed IMO.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in #63.

});

describe('Workspace.listUseableConnectors(cb)', function () {
it('should return a list of connectors in package.json');
});


describe('project.listAvailableConnectors(cb)', function() {
before(function(done) {
Workspace.listAvailableConnectors(function(err, list) {
Expand Down