unsakini 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +34 -0
- data/angular/README.md +31 -0
- data/angular/angular-cli.json +59 -0
- data/angular/karma.conf.js +45 -0
- data/angular/package.json +49 -0
- data/angular/protractor.conf.js +32 -0
- data/angular/src/app/app.component.css +0 -0
- data/angular/src/app/app.component.html +4 -0
- data/angular/src/app/app.component.spec.ts +47 -0
- data/angular/src/app/app.component.ts +10 -0
- data/angular/src/app/app.module.ts +29 -0
- data/angular/src/app/app.routes.module.ts +29 -0
- data/angular/src/app/index.ts +2 -0
- data/angular/src/app/registration/registration.component.css +0 -0
- data/angular/src/app/registration/registration.component.html +14 -0
- data/angular/src/app/registration/registration.component.spec.ts +157 -0
- data/angular/src/app/registration/registration.component.ts +42 -0
- data/angular/src/environments/environment.prod.ts +3 -0
- data/angular/src/environments/environment.ts +8 -0
- data/angular/src/favicon.ico +0 -0
- data/angular/src/index.html +14 -0
- data/angular/src/main.ts +12 -0
- data/angular/src/polyfills.ts +19 -0
- data/angular/src/styles.css +1 -0
- data/angular/src/test.ts +31 -0
- data/angular/src/tsconfig.json +18 -0
- data/angular/src/typings.d.ts +2 -0
- data/angular/tslint.json +114 -0
- data/angular/typings.json +4 -0
- data/app/controllers/api/boards_controller.rb +67 -0
- data/app/controllers/api/comments_controller.rb +51 -0
- data/app/controllers/api/posts_controller.rb +58 -0
- data/app/controllers/api/share_board_controller.rb +118 -0
- data/app/controllers/api/users_controller.rb +27 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/concerns/board_owner_controller_concern.rb +38 -0
- data/app/controllers/concerns/comment_owner_controller_concern.rb +33 -0
- data/app/controllers/concerns/logged_in_controller_concern.rb +21 -0
- data/app/controllers/concerns/post_owner_controller_concern.rb +36 -0
- data/app/controllers/concerns/serializer_controller_concern.rb +11 -0
- data/app/controllers/user_token_controller.rb +2 -0
- data/app/controllers/web_base_controller.rb +11 -0
- data/app/models/application_record.rb +5 -0
- data/app/models/board.rb +14 -0
- data/app/models/comment.rb +9 -0
- data/app/models/concerns/encryptable_model_concern.rb +96 -0
- data/app/models/post.rb +12 -0
- data/app/models/user.rb +6 -0
- data/app/models/user_board.rb +71 -0
- data/app/serializers/board_serializer.rb +5 -0
- data/app/serializers/comment_serializer.rb +10 -0
- data/app/serializers/post_serializer.rb +23 -0
- data/app/serializers/user_board_serializer.rb +10 -0
- data/app/serializers/user_serializer.rb +6 -0
- data/config/initializers/unsakini.rb +4 -0
- data/config/routes.rb +22 -0
- data/db/migrate/20161116114222_create_boards.rb +9 -0
- data/db/migrate/20161116200034_create_user_boards.rb +11 -0
- data/db/migrate/20161118031023_create_posts.rb +12 -0
- data/db/migrate/20161118100454_create_comments.rb +11 -0
- data/db/migrate/20161118221508_add_encrypted_password_to_user_board.rb +5 -0
- data/db/migrate/20161122211105_create_users.rb +12 -0
- data/lib/generators/unsakini/angular/USAGE +8 -0
- data/lib/generators/unsakini/angular/angular_generator.rb +7 -0
- data/lib/generators/unsakini/config/USAGE +8 -0
- data/lib/generators/unsakini/config/config_generator.rb +7 -0
- data/lib/generators/unsakini/config/templates/unsakini.rb +4 -0
- data/lib/tasks/unsakini_tasks.rake +33 -0
- data/lib/unsakini/engine.rb +30 -0
- data/lib/unsakini/version.rb +3 -0
- data/lib/unsakini.rb +5 -0
- data/spec/concerns/models/encryptable_concern.rb +40 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/angular/README.md +31 -0
- data/spec/dummy/angular/angular-cli.json +59 -0
- data/spec/dummy/angular/e2e/app.e2e-spec.ts +14 -0
- data/spec/dummy/angular/e2e/app.po.ts +11 -0
- data/spec/dummy/angular/e2e/signup.e2e-spec.ts +28 -0
- data/spec/dummy/angular/e2e/signup.po.ts +31 -0
- data/spec/dummy/angular/e2e/tsconfig.json +16 -0
- data/spec/dummy/angular/karma.conf.js +45 -0
- data/spec/dummy/angular/package.json +50 -0
- data/spec/dummy/angular/protractor.conf.js +32 -0
- data/spec/dummy/angular/src/app/app.component.css +0 -0
- data/spec/dummy/angular/src/app/app.component.html +4 -0
- data/spec/dummy/angular/src/app/app.component.spec.ts +47 -0
- data/spec/dummy/angular/src/app/app.component.ts +10 -0
- data/spec/dummy/angular/src/app/app.module.ts +29 -0
- data/spec/dummy/angular/src/app/app.routes.module.ts +29 -0
- data/spec/dummy/angular/src/app/index.ts +2 -0
- data/spec/dummy/angular/src/app/registration/registration.component.css +0 -0
- data/spec/dummy/angular/src/app/registration/registration.component.html +14 -0
- data/spec/dummy/angular/src/app/registration/registration.component.spec.ts +157 -0
- data/spec/dummy/angular/src/app/registration/registration.component.ts +42 -0
- data/spec/dummy/angular/src/environments/environment.prod.ts +3 -0
- data/spec/dummy/angular/src/environments/environment.ts +8 -0
- data/spec/dummy/angular/src/favicon.ico +0 -0
- data/spec/dummy/angular/src/index.html +14 -0
- data/spec/dummy/angular/src/main.ts +12 -0
- data/spec/dummy/angular/src/polyfills.ts +19 -0
- data/spec/dummy/angular/src/styles.css +1 -0
- data/spec/dummy/angular/src/test.ts +31 -0
- data/spec/dummy/angular/src/tsconfig.json +18 -0
- data/spec/dummy/angular/src/typings.d.ts +2 -0
- data/spec/dummy/angular/tslint.json +114 -0
- data/spec/dummy/angular/typings.json +4 -0
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +34 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/config/application.rb +22 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +9 -0
- data/spec/dummy/config/crypto.yml +7 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +47 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cors.rb +16 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/new_framework_defaults.rb +18 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/puma.rb +47 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +56 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/app/favicon.ico +0 -0
- data/spec/dummy/public/app/index.html +14 -0
- data/spec/dummy/public/app/inline.bundle.js +139 -0
- data/spec/dummy/public/app/inline.map +1 -0
- data/spec/dummy/public/app/main.bundle.js +64689 -0
- data/spec/dummy/public/app/main.map +1 -0
- data/spec/dummy/public/app/styles.bundle.js +364 -0
- data/spec/dummy/public/app/styles.map +1 -0
- data/spec/factories/boards.rb +5 -0
- data/spec/factories/comments.rb +7 -0
- data/spec/factories/posts.rb +8 -0
- data/spec/factories/user_boards.rb +9 -0
- data/spec/factories/users.rb +10 -0
- data/spec/models/board_spec.rb +19 -0
- data/spec/models/comment_spec.rb +26 -0
- data/spec/models/post_spec.rb +19 -0
- data/spec/models/user_board_spec.rb +193 -0
- data/spec/models/user_spec.rb +5 -0
- data/spec/rails_helper.rb +58 -0
- data/spec/requests/api/api_boards_spec.rb +238 -0
- data/spec/requests/api/api_share_board_spec.rb +167 -0
- data/spec/requests/api/api_users_spec.rb +52 -0
- data/spec/requests/api/board/api_board_posts_spec.rb +299 -0
- data/spec/requests/api/board/post/api_board_post_comments_spec.rb +370 -0
- data/spec/requests/render_app_index_spec.rb +19 -0
- data/spec/schema/board.json +39 -0
- data/spec/schema/comment.json +51 -0
- data/spec/schema/post.json +87 -0
- data/spec/schema/user.json +27 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/auth_helper.rb +17 -0
- data/spec/support/scenario_helper.rb +134 -0
- data/spec/support/serialize_helper.rb +37 -0
- metadata +540 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
// import { AngularPage } from './app.po';
|
2
|
+
|
3
|
+
// describe('angular App', function() {
|
4
|
+
// let page: AngularPage;
|
5
|
+
|
6
|
+
// beforeEach(() => {
|
7
|
+
// page = new AngularPage();
|
8
|
+
// });
|
9
|
+
|
10
|
+
// it('should display message saying app works', () => {
|
11
|
+
// page.navigateTo();
|
12
|
+
// expect(page.getParagraphText()).toEqual('app works!');
|
13
|
+
// });
|
14
|
+
// });
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { browser, element, by, ExpectedConditions } from 'protractor';
|
2
|
+
|
3
|
+
import { SignUpPage } from './signup.po';
|
4
|
+
|
5
|
+
describe('Registration Page', function() {
|
6
|
+
let page: SignUpPage;
|
7
|
+
|
8
|
+
beforeAll(() => {
|
9
|
+
page = new SignUpPage();
|
10
|
+
page.navigateTo();
|
11
|
+
});
|
12
|
+
|
13
|
+
it('shows vadiation errors', () => {
|
14
|
+
page.fillForm({
|
15
|
+
name: 'me',
|
16
|
+
email: 'hello@world.com',
|
17
|
+
password: '',
|
18
|
+
password_confirmation: ''
|
19
|
+
})
|
20
|
+
|
21
|
+
page.submit();
|
22
|
+
|
23
|
+
page.hasError('Password')
|
24
|
+
|
25
|
+
});
|
26
|
+
|
27
|
+
|
28
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { browser, element, by, ExpectedConditions } from 'protractor';
|
2
|
+
export class SignUpPage {
|
3
|
+
navigateTo() {
|
4
|
+
return browser.get('/app/registration');
|
5
|
+
}
|
6
|
+
|
7
|
+
fillForm({name, email, password, password_confirmation}) {
|
8
|
+
let form = element(by.tagName('form'));
|
9
|
+
let name_input = element(by.css('input[name="name"]'))
|
10
|
+
let email_input = element(by.css('input[name="email"]'))
|
11
|
+
let password_input = element(by.css('input[name="password"]'))
|
12
|
+
let password_confirmation_input = element(by.css('input[name="password_confirmation"]'))
|
13
|
+
|
14
|
+
name_input.sendKeys(name);
|
15
|
+
email_input.sendKeys(email);
|
16
|
+
password_input.sendKeys(password);
|
17
|
+
password_confirmation_input.sendKeys(password_confirmation);
|
18
|
+
}
|
19
|
+
|
20
|
+
submit() {
|
21
|
+
|
22
|
+
let button = element(by.tagName('button'))
|
23
|
+
button.click()
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
hasError(str) {
|
28
|
+
expect(element(by.css('.alert-danger')).getText()).toContain(str)
|
29
|
+
}
|
30
|
+
|
31
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"compileOnSave": false,
|
3
|
+
"compilerOptions": {
|
4
|
+
"declaration": false,
|
5
|
+
"emitDecoratorMetadata": true,
|
6
|
+
"experimentalDecorators": true,
|
7
|
+
"module": "commonjs",
|
8
|
+
"moduleResolution": "node",
|
9
|
+
"outDir": "../dist/out-tsc-e2e",
|
10
|
+
"sourceMap": true,
|
11
|
+
"target": "es5",
|
12
|
+
"typeRoots": [
|
13
|
+
"../node_modules/@types"
|
14
|
+
]
|
15
|
+
}
|
16
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
// Karma configuration file, see link for more information
|
2
|
+
// https://karma-runner.github.io/0.13/config/configuration-file.html
|
3
|
+
|
4
|
+
module.exports = function (config) {
|
5
|
+
config.set({
|
6
|
+
basePath: '',
|
7
|
+
frameworks: ['jasmine', 'angular-cli'],
|
8
|
+
plugins: [
|
9
|
+
require('karma-jasmine'),
|
10
|
+
require('karma-phantomjs-launcher'),
|
11
|
+
// require('karma-chrome-launcher'),
|
12
|
+
require('karma-remap-istanbul'),
|
13
|
+
require('angular-cli/plugins/karma')
|
14
|
+
],
|
15
|
+
files: [
|
16
|
+
{ pattern: './src/test.ts', watched: false }
|
17
|
+
],
|
18
|
+
preprocessors: {
|
19
|
+
'./src/test.ts': ['angular-cli']
|
20
|
+
},
|
21
|
+
mime: {
|
22
|
+
'text/x-typescript': ['ts','tsx']
|
23
|
+
},
|
24
|
+
remapIstanbulReporter: {
|
25
|
+
reports: {
|
26
|
+
html: 'coverage',
|
27
|
+
lcovonly: './coverage/coverage.lcov'
|
28
|
+
}
|
29
|
+
},
|
30
|
+
angularCli: {
|
31
|
+
config: './angular-cli.json',
|
32
|
+
environment: 'dev'
|
33
|
+
},
|
34
|
+
reporters: config.angularCli && config.angularCli.codeCoverage
|
35
|
+
? ['progress', 'karma-remap-istanbul']
|
36
|
+
: ['progress'],
|
37
|
+
port: 9874,
|
38
|
+
colors: true,
|
39
|
+
logLevel: config.LOG_INFO,
|
40
|
+
autoWatch: true,
|
41
|
+
// browsers: ['Chrome'],
|
42
|
+
browsers: ['PhantomJS'],
|
43
|
+
singleRun: false
|
44
|
+
});
|
45
|
+
};
|
@@ -0,0 +1,50 @@
|
|
1
|
+
{
|
2
|
+
"name": "angular",
|
3
|
+
"version": "0.0.0",
|
4
|
+
"license": "MIT",
|
5
|
+
"angular-cli": {},
|
6
|
+
"scripts": {
|
7
|
+
"start": "ng serve",
|
8
|
+
"lint": "tslint \"src/**/*.ts\"",
|
9
|
+
"test": "ng test",
|
10
|
+
"pree2e": "webdriver-manager update",
|
11
|
+
"e2e": "protractor",
|
12
|
+
"postinstall": "ng build"
|
13
|
+
},
|
14
|
+
"private": true,
|
15
|
+
"dependencies": {
|
16
|
+
"@angular/common": "^2.1.0",
|
17
|
+
"@angular/compiler": "^2.1.0",
|
18
|
+
"@angular/core": "^2.1.0",
|
19
|
+
"@angular/forms": "^2.1.0",
|
20
|
+
"@angular/http": "^2.1.0",
|
21
|
+
"@angular/platform-browser": "^2.1.0",
|
22
|
+
"@angular/platform-browser-dynamic": "^2.1.0",
|
23
|
+
"@angular/router": "^3.1.0",
|
24
|
+
"angular2-token": "^0.2.0-beta.3",
|
25
|
+
"core-js": "^2.4.1",
|
26
|
+
"rxjs": "5.0.0-beta.12",
|
27
|
+
"ts-helpers": "^1.1.1",
|
28
|
+
"zone.js": "^0.6.23"
|
29
|
+
},
|
30
|
+
"devDependencies": {
|
31
|
+
"@angular/compiler-cli": "^2.1.0",
|
32
|
+
"@types/jasmine": "^2.2.30",
|
33
|
+
"@types/node": "^6.0.42",
|
34
|
+
"angular-cli": "1.0.0-beta.20-4",
|
35
|
+
"codelyzer": "~1.0.0-beta.3",
|
36
|
+
"jasmine-core": "2.4.1",
|
37
|
+
"jasmine-spec-reporter": "2.5.0",
|
38
|
+
"karma": "1.2.0",
|
39
|
+
"karma-chrome-launcher": "^2.0.0",
|
40
|
+
"karma-cli": "^1.0.1",
|
41
|
+
"karma-jasmine": "^1.0.2",
|
42
|
+
"karma-phantomjs-launcher": "^1.0.2",
|
43
|
+
"karma-remap-istanbul": "^0.2.1",
|
44
|
+
"protractor": "4.0.9",
|
45
|
+
"ts-node": "1.2.1",
|
46
|
+
"tslint": "3.13.0",
|
47
|
+
"typescript": "~2.0.3",
|
48
|
+
"webdriver-manager": "10.2.5"
|
49
|
+
}
|
50
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
// Protractor configuration file, see link for more information
|
2
|
+
// https://github.com/angular/protractor/blob/master/docs/referenceConf.js
|
3
|
+
|
4
|
+
/*global jasmine */
|
5
|
+
var SpecReporter = require('jasmine-spec-reporter');
|
6
|
+
|
7
|
+
exports.config = {
|
8
|
+
allScriptsTimeout: 11000,
|
9
|
+
specs: [
|
10
|
+
'./e2e/**/*.e2e-spec.ts'
|
11
|
+
],
|
12
|
+
capabilities: {
|
13
|
+
'browserName': 'chrome'
|
14
|
+
},
|
15
|
+
directConnect: true,
|
16
|
+
baseUrl: 'http://localhost:3000/app/',
|
17
|
+
framework: 'jasmine',
|
18
|
+
jasmineNodeOpts: {
|
19
|
+
showColors: true,
|
20
|
+
defaultTimeoutInterval: 30000,
|
21
|
+
print: function() {}
|
22
|
+
},
|
23
|
+
useAllAngular2AppRoots: true,
|
24
|
+
beforeLaunch: function() {
|
25
|
+
require('ts-node').register({
|
26
|
+
project: 'e2e'
|
27
|
+
});
|
28
|
+
},
|
29
|
+
onPrepare: function() {
|
30
|
+
jasmine.getEnv().addReporter(new SpecReporter());
|
31
|
+
}
|
32
|
+
};
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/* tslint:disable:no-unused-variable */
|
2
|
+
|
3
|
+
import { TestBed, async } from '@angular/core/testing';
|
4
|
+
import { AppComponent } from './app.component';
|
5
|
+
import { RouterTestingModule } from '@angular/router/testing';
|
6
|
+
|
7
|
+
describe('AppComponent', () => {
|
8
|
+
|
9
|
+
beforeEach(() => {
|
10
|
+
TestBed.configureTestingModule({
|
11
|
+
imports: [
|
12
|
+
RouterTestingModule
|
13
|
+
],
|
14
|
+
declarations:
|
15
|
+
[
|
16
|
+
AppComponent
|
17
|
+
],
|
18
|
+
});
|
19
|
+
});
|
20
|
+
|
21
|
+
it('should create the app', async(() => {
|
22
|
+
let fixture = TestBed.createComponent(AppComponent);
|
23
|
+
let app = fixture.debugElement.componentInstance;
|
24
|
+
expect(app).toBeTruthy();
|
25
|
+
}));
|
26
|
+
|
27
|
+
it(`should have as title 'app works!'`, async(() => {
|
28
|
+
let fixture = TestBed.createComponent(AppComponent);
|
29
|
+
let app = fixture.debugElement.componentInstance;
|
30
|
+
expect(app.title).toEqual('app works!');
|
31
|
+
}));
|
32
|
+
|
33
|
+
it('should render title in a h1 tag', async(() => {
|
34
|
+
let fixture = TestBed.createComponent(AppComponent);
|
35
|
+
fixture.detectChanges();
|
36
|
+
let compiled = fixture.debugElement.nativeElement;
|
37
|
+
expect(compiled.querySelector('h1').textContent).toContain('app works!');
|
38
|
+
}));
|
39
|
+
|
40
|
+
it('should have router outlet', async(() => {
|
41
|
+
let fixture = TestBed.createComponent(AppComponent);
|
42
|
+
fixture.detectChanges();
|
43
|
+
let compiled = fixture.debugElement.nativeElement;
|
44
|
+
expect(compiled.querySelector('router-outlet')).toBeTruthy()
|
45
|
+
}));
|
46
|
+
|
47
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { BrowserModule } from '@angular/platform-browser';
|
2
|
+
import { NgModule } from '@angular/core';
|
3
|
+
import { FormsModule } from '@angular/forms';
|
4
|
+
import { HttpModule } from '@angular/http';
|
5
|
+
import { Angular2TokenService, A2tUiModule } from 'angular2-token';
|
6
|
+
|
7
|
+
import { AppRoutesModule } from './app.routes.module';
|
8
|
+
|
9
|
+
import { AppComponent } from './app.component';
|
10
|
+
import { RegistrationComponent } from './registration/registration.component';
|
11
|
+
|
12
|
+
@NgModule({
|
13
|
+
imports: [
|
14
|
+
BrowserModule,
|
15
|
+
FormsModule,
|
16
|
+
HttpModule,
|
17
|
+
AppRoutesModule,
|
18
|
+
A2tUiModule,
|
19
|
+
],
|
20
|
+
declarations: [
|
21
|
+
AppComponent,
|
22
|
+
RegistrationComponent
|
23
|
+
],
|
24
|
+
providers: [
|
25
|
+
Angular2TokenService,
|
26
|
+
],
|
27
|
+
bootstrap: [AppComponent]
|
28
|
+
})
|
29
|
+
export class AppModule { }
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { NgModule } from '@angular/core';
|
2
|
+
import { RouterModule } from '@angular/router';
|
3
|
+
|
4
|
+
import { RegistrationComponent } from './registration/registration.component'
|
5
|
+
|
6
|
+
|
7
|
+
const routes = [
|
8
|
+
{
|
9
|
+
path: '',
|
10
|
+
redirectTo: 'registration',
|
11
|
+
pathMatch: 'full'
|
12
|
+
},
|
13
|
+
{
|
14
|
+
path: 'registration',
|
15
|
+
component: RegistrationComponent
|
16
|
+
}
|
17
|
+
];
|
18
|
+
|
19
|
+
@NgModule({
|
20
|
+
imports: [
|
21
|
+
RouterModule.forRoot(routes)
|
22
|
+
],
|
23
|
+
exports: [
|
24
|
+
RouterModule
|
25
|
+
],
|
26
|
+
providers: []
|
27
|
+
})
|
28
|
+
|
29
|
+
export class AppRoutesModule {}
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
<form (ngSubmit)="doSubmit()">
|
3
|
+
<div class="alert alert-success" *ngIf="success">Registration successful. Please confirm your email sent to {{user.email}} to proceed.</div>
|
4
|
+
<div class="alert alert-danger" *ngIf="errors">
|
5
|
+
<p *ngFor="let e of errors">{{e}}</p>
|
6
|
+
</div>
|
7
|
+
<input type="text" name="name">
|
8
|
+
<input type="email" name="email">
|
9
|
+
<input type="password" name="password">
|
10
|
+
<input type="password" name="password_confirmation">
|
11
|
+
<button type="submit">Sign Up</button>
|
12
|
+
</form>
|
13
|
+
|
14
|
+
<div (click)="doSubmit()">CLICK ME</div>
|
@@ -0,0 +1,157 @@
|
|
1
|
+
/* tslint:disable:no-unused-variable */
|
2
|
+
|
3
|
+
import { inject, async, ComponentFixture, TestBed } from '@angular/core/testing';
|
4
|
+
import { Observable } from 'rxjs/Observable';
|
5
|
+
import 'rxjs/add/observable/of';
|
6
|
+
import 'rxjs/add/observable/throw';
|
7
|
+
import { By } from '@angular/platform-browser';
|
8
|
+
import { DebugElement } from '@angular/core';
|
9
|
+
import { Angular2TokenService } from 'angular2-token';
|
10
|
+
|
11
|
+
import { RegistrationComponent } from './registration.component';
|
12
|
+
|
13
|
+
let user = {
|
14
|
+
name: 'first last',
|
15
|
+
email: 'hello@world.com',
|
16
|
+
password: null,
|
17
|
+
password_confirmation: null
|
18
|
+
}
|
19
|
+
|
20
|
+
let status = 0
|
21
|
+
let errors = []
|
22
|
+
|
23
|
+
class Angular2TokenServiceMock {
|
24
|
+
registerAccount(user) {
|
25
|
+
|
26
|
+
if (status === 200) {
|
27
|
+
return Observable.of({
|
28
|
+
status: 200,
|
29
|
+
json: () => {
|
30
|
+
return {
|
31
|
+
user
|
32
|
+
}
|
33
|
+
}
|
34
|
+
});
|
35
|
+
} else {
|
36
|
+
return Observable.throw({
|
37
|
+
status: status,
|
38
|
+
json: () => {
|
39
|
+
return {
|
40
|
+
errors: errors
|
41
|
+
}
|
42
|
+
}
|
43
|
+
});
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
describe('RegistrationComponent', () => {
|
49
|
+
let component: RegistrationComponent;
|
50
|
+
let fixture: ComponentFixture<RegistrationComponent>;
|
51
|
+
let compiled: any;
|
52
|
+
|
53
|
+
beforeEach(async(() => {
|
54
|
+
TestBed.configureTestingModule({
|
55
|
+
imports: [
|
56
|
+
],
|
57
|
+
declarations: [RegistrationComponent],
|
58
|
+
providers: [
|
59
|
+
{
|
60
|
+
provide: Angular2TokenService,
|
61
|
+
useClass: Angular2TokenServiceMock
|
62
|
+
},
|
63
|
+
]
|
64
|
+
})
|
65
|
+
.compileComponents();
|
66
|
+
}));
|
67
|
+
|
68
|
+
beforeEach(() => {
|
69
|
+
fixture = TestBed.createComponent(RegistrationComponent);
|
70
|
+
component = fixture.componentInstance;
|
71
|
+
compiled = fixture.debugElement.nativeElement;
|
72
|
+
fixture.detectChanges();
|
73
|
+
});
|
74
|
+
|
75
|
+
describe('Component', () => {
|
76
|
+
|
77
|
+
it('should create', () => {
|
78
|
+
expect(component).toBeTruthy();
|
79
|
+
});
|
80
|
+
|
81
|
+
it('should have token service', () => {
|
82
|
+
expect(component.service).toBeDefined();
|
83
|
+
});
|
84
|
+
|
85
|
+
it('should have user', () => {
|
86
|
+
expect(component.user).toEqual({
|
87
|
+
name: '',
|
88
|
+
email: '',
|
89
|
+
password: '',
|
90
|
+
password_confirmation: ''
|
91
|
+
});
|
92
|
+
});
|
93
|
+
|
94
|
+
it('should handle http 422', () => {
|
95
|
+
status = 422
|
96
|
+
errors = ['some errors']
|
97
|
+
component.user = user
|
98
|
+
component.doSubmit()
|
99
|
+
expect(component.success).toBe(false)
|
100
|
+
expect(component.errors).toEqual(errors)
|
101
|
+
fixture.detectChanges();
|
102
|
+
expect(compiled.querySelector('.alert-success')).toBeFalsy()
|
103
|
+
expect(compiled.querySelector('.alert-danger').textContent).toContain('some errors')
|
104
|
+
})
|
105
|
+
|
106
|
+
it('should handle http 500 and other errors', () => {
|
107
|
+
status = 500
|
108
|
+
component.user = user
|
109
|
+
component.doSubmit()
|
110
|
+
expect(component.success).toBe(false)
|
111
|
+
expect(component.errors).toEqual(['Something went wrong.'])
|
112
|
+
fixture.detectChanges();
|
113
|
+
expect(compiled.querySelector('.alert-success')).toBeFalsy()
|
114
|
+
expect(compiled.querySelector('.alert-danger').textContent).toContain('Something went wrong')
|
115
|
+
})
|
116
|
+
|
117
|
+
it('should notify when success', () => {
|
118
|
+
component.user = user
|
119
|
+
status = 200
|
120
|
+
component.doSubmit()
|
121
|
+
expect(component.success).toBe(true)
|
122
|
+
fixture.detectChanges();
|
123
|
+
expect(compiled.querySelector('.alert-success')).toBeTruthy()
|
124
|
+
expect(compiled.querySelector('.alert-success').textContent).toContain('Registration successful')
|
125
|
+
})
|
126
|
+
|
127
|
+
});
|
128
|
+
|
129
|
+
describe('View', () => {
|
130
|
+
|
131
|
+
it('should have form', () => {
|
132
|
+
expect(compiled.querySelector('form')).toBeTruthy();
|
133
|
+
});
|
134
|
+
|
135
|
+
it('should have input name', () => {
|
136
|
+
expect(compiled.querySelector('input[name="name"]')).toBeTruthy();
|
137
|
+
});
|
138
|
+
|
139
|
+
it('should have input email', () => {
|
140
|
+
expect(compiled.querySelector('input[name="email"][type="email"]')).toBeTruthy();
|
141
|
+
});
|
142
|
+
|
143
|
+
it('should have input password', () => {
|
144
|
+
expect(compiled.querySelector('input[name="password"][type="password"]')).toBeTruthy();
|
145
|
+
});
|
146
|
+
|
147
|
+
it('should have input password confirmation', () => {
|
148
|
+
expect(compiled.querySelector('input[name="password_confirmation"][type="password"]')).toBeTruthy();
|
149
|
+
});
|
150
|
+
|
151
|
+
it('should have submit button', () => {
|
152
|
+
expect(compiled.querySelector('button[type="submit"]')).toBeTruthy();
|
153
|
+
});
|
154
|
+
|
155
|
+
});
|
156
|
+
|
157
|
+
});
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { Component, OnInit } from '@angular/core';
|
2
|
+
import { Angular2TokenService } from 'angular2-token';
|
3
|
+
|
4
|
+
@Component({
|
5
|
+
selector: 'app-registration',
|
6
|
+
templateUrl: './registration.component.html',
|
7
|
+
styleUrls: ['./registration.component.css']
|
8
|
+
})
|
9
|
+
export class RegistrationComponent implements OnInit {
|
10
|
+
|
11
|
+
user: any;
|
12
|
+
errors: any;
|
13
|
+
success = false;
|
14
|
+
|
15
|
+
constructor(public service: Angular2TokenService) {
|
16
|
+
this.user = {
|
17
|
+
name: '',
|
18
|
+
email: '',
|
19
|
+
password: '',
|
20
|
+
password_confirmation: ''
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
doSubmit () {
|
25
|
+
this.service.registerAccount(this.user).subscribe(
|
26
|
+
(res) => {
|
27
|
+
this.success = true;
|
28
|
+
},
|
29
|
+
(res) => {
|
30
|
+
if (res.status == 422) {
|
31
|
+
this.errors = res.json().errors
|
32
|
+
} else {
|
33
|
+
this.errors = ['Something went wrong.']
|
34
|
+
}
|
35
|
+
}
|
36
|
+
);
|
37
|
+
}
|
38
|
+
|
39
|
+
ngOnInit() {
|
40
|
+
}
|
41
|
+
|
42
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
// The file contents for the current environment will overwrite these during build.
|
2
|
+
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
|
3
|
+
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
|
4
|
+
// The list of which env maps to which file can be found in `angular-cli.json`.
|
5
|
+
|
6
|
+
export const environment = {
|
7
|
+
production: false
|
8
|
+
};
|
Binary file
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Angular</title>
|
6
|
+
<base href="/app/">
|
7
|
+
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
9
|
+
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<app-root>Loading...</app-root>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import './polyfills.ts';
|
2
|
+
|
3
|
+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
4
|
+
import { enableProdMode } from '@angular/core';
|
5
|
+
import { environment } from './environments/environment';
|
6
|
+
import { AppModule } from './app/';
|
7
|
+
|
8
|
+
if (environment.production) {
|
9
|
+
enableProdMode();
|
10
|
+
}
|
11
|
+
|
12
|
+
platformBrowserDynamic().bootstrapModule(AppModule);
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// This file includes polyfills needed by Angular 2 and is loaded before
|
2
|
+
// the app. You can add your own extra polyfills to this file.
|
3
|
+
import 'core-js/es6/symbol';
|
4
|
+
import 'core-js/es6/object';
|
5
|
+
import 'core-js/es6/function';
|
6
|
+
import 'core-js/es6/parse-int';
|
7
|
+
import 'core-js/es6/parse-float';
|
8
|
+
import 'core-js/es6/number';
|
9
|
+
import 'core-js/es6/math';
|
10
|
+
import 'core-js/es6/string';
|
11
|
+
import 'core-js/es6/date';
|
12
|
+
import 'core-js/es6/array';
|
13
|
+
import 'core-js/es6/regexp';
|
14
|
+
import 'core-js/es6/map';
|
15
|
+
import 'core-js/es6/set';
|
16
|
+
import 'core-js/es6/reflect';
|
17
|
+
|
18
|
+
import 'core-js/es7/reflect';
|
19
|
+
import 'zone.js/dist/zone';
|
@@ -0,0 +1 @@
|
|
1
|
+
/* You can add global styles to this file, and also import other style files */
|