Skip to content

Commit 2d44417

Browse files
- enhancement: added sims for mocking backend requests for authenticating an user (see conjoon/extjs-app-imapuser#2)
1 parent 7ad5674 commit 2d44417

File tree

13 files changed

+423
-3
lines changed

13 files changed

+423
-3
lines changed

LICENSE renamed to LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 conjoon
3+
Copyright (c) 2019 Thorsten Suckow-Homberg https://github.com/conjoon/dev-cn_imapusersim
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
1-
# dev-cn_imapusersim
2-
Dev package for mocking backend requests and data for conjoon/app-cn_imapuser
1+
# dev-cn_mailsim [![Build Status](https://travis-ci.org/conjoon/dev-cn_mailsim.svg?branch=master)](https://travis-ci.org/conjoon/dev-cn_imapusersim)
2+
This **Sencha ExtJS** package contains mock data for development of [conjoon/app-cn_imapuser](https://github.com/conjoon/app-cn_imapuser).
3+
When using this package, all backend requests of app-cn_imapuser will be replaced with mocks.
4+
5+
6+
## Naming
7+
The following naming conventions apply:
8+
9+
#### Namespace
10+
`conjoon.dev.cn_imapusersim.*`
11+
#### Package name
12+
`dev-cn_imapusersim`
13+
#### Shorthand to be used with providing aliases
14+
`cn_imapusersim`
15+
16+
# Usage
17+
## Requirements
18+
This package requires the [lib-cn_core](https://github.com/coon-js/lib-cn_core) package of the [coon.js](https://github.com/coon-js) project.
19+
20+
# Usage
21+
Simply update the app.json of the conjoon-application
22+
by specifying this package in the `uses`-property in either the `development` and/or `prodution` section:
23+
24+
*Example:*
25+
````javascript
26+
"development": {
27+
"uses" : [
28+
"app-cn_imapusersim",
29+
"app-cn_imapuser",
30+
"app-cn_mail",
31+
"dev-cn_mailsim"
32+
]
33+
},
34+
"production": {
35+
"uses" : [
36+
"app-cn_imapuser",
37+
"app-cn_mail"
38+
]
39+
}
40+
````
41+
42+
Notice how in the example above all backend requests made by the [app-cn_imapusersim](https://github.com/conjoon/app-cn_imapusersim) package
43+
will be intercepted by the backend-mocks of the `dev-cn_imapusersim` package when using the development-version.

build.xml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<project name="dev-cn_imapusersim" default=".help">
3+
4+
<script language="javascript">
5+
<![CDATA[
6+
var dir = project.getProperty("basedir"),
7+
cmdDir = project.getProperty("cmd.dir"),
8+
cmdLoaded = project.getReference("senchaloader");
9+
10+
if (!cmdLoaded) {
11+
function echo(message, file) {
12+
var e = project.createTask("echo");
13+
e.setMessage(message);
14+
if (file) {
15+
e.setFile(file);
16+
}
17+
e.execute();
18+
};
19+
20+
if (!cmdDir) {
21+
22+
function exec(args) {
23+
var process = java.lang.Runtime.getRuntime().exec(args),
24+
input = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream())),
25+
headerFound = false,
26+
line;
27+
28+
while (line = input.readLine()) {
29+
line = line + '';
30+
java.lang.System.out.println(line);
31+
if (line.indexOf("Sencha Cmd") > -1) {
32+
headerFound = true;
33+
}
34+
else if (headerFound && !cmdDir) {
35+
cmdDir = line;
36+
project.setProperty("cmd.dir", cmdDir);
37+
}
38+
}
39+
process.waitFor();
40+
return !!cmdDir;
41+
}
42+
43+
if (!exec(["sencha", "which"])) {
44+
var tmpFile = "tmp.sh";
45+
echo("source ~/.bash_profile; sencha " + whichArgs.join(" "), tmpFile);
46+
exec(["/bin/sh", tmpFile]);
47+
new java.io.File(tmpFile)['delete']();
48+
}
49+
}
50+
}
51+
52+
if (cmdDir && !project.getTargets().containsKey("init-cmd")) {
53+
var importDir = project.getProperty("build-impl.dir") ||
54+
(cmdDir + "/ant/build/package/build-impl.xml");
55+
var importTask = project.createTask("import");
56+
57+
importTask.setOwningTarget(self.getOwningTarget());
58+
importTask.setLocation(self.getLocation());
59+
importTask.setFile(importDir);
60+
importTask.execute();
61+
}
62+
]]>
63+
</script>
64+
65+
<!--
66+
The following targets can be provided to inject logic before and/or after key steps
67+
of the build process:
68+
69+
The "init-local" target is used to initialize properties that may be personalized
70+
for the local machine.
71+
72+
<target name="-before-init-local"/>
73+
<target name="-after-init-local"/>
74+
75+
The "clean" target is used to clean build output from the build.dir.
76+
77+
<target name="-before-clean"/>
78+
<target name="-after-clean"/>
79+
80+
The general "init" target is used to initialize all other properties, including
81+
those provided by Sencha Cmd.
82+
83+
<target name="-before-init"/>
84+
<target name="-after-init"/>
85+
86+
The "build" target performs the call to Sencha Cmd to build the application.
87+
88+
<target name="-before-build"/>
89+
<target name="-after-build"/>
90+
-->
91+
92+
</project>

build/dev-cn_imapusersim-debug.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Ext.define('conjoon.dev.cn_imapusersim.data.imapuser.ajax.sim.Init', {requires:['Ext.ux.ajax.JsonSimlet', 'Ext.ux.ajax.SimManager'], singleton:true, constructor:function() {
2+
Ext.ux.ajax.SimManager.init({delay:1, defaultSimlet:null});
3+
}});
4+
Ext.define('conjoon.dev.cn_imapusersim.data.imapuser.ajax.sim.auth.AuthenticationSim', {requires:['conjoon.dev.cn_imapusersim.data.imapuser.ajax.sim.Init']}, function() {
5+
Ext.ux.ajax.SimManager.register({type:'json', url:/cn_imapuser\/auth(\/\d+)?/, doPost:function(ctx) {
6+
const me = this, params = ctx.xhr.options.params, username = params.username, password = params.password, ret = {};
7+
ret.responseText = Ext.JSON.encode({data:{firstname:'John', lastname:'Smith', username:username, emailAddress:username, isRoot:false, lastLogin:new Date, password:password}});
8+
Ext.Array.forEach(me.responseProps, function(prop) {
9+
if (prop in me) {
10+
ret[prop] = me[prop];
11+
}
12+
});
13+
if (username === 'TESTFAIL') {
14+
ret.status = 401;
15+
}
16+
return ret;
17+
}});
18+
});
19+
Ext.define('conjoon.dev.cn_imapusersim.data.imapuser.PackageSim', {requires:['conjoon.dev.cn_imapusersim.data.imapuser.ajax.sim.auth.AuthenticationSim']});
20+
Ext.define('conjoon.dev.cn_imapusersim.app.PackageController', {extend:'coon.core.app.PackageController', requires:['conjoon.dev.cn_imapusersim.data.imapuser.PackageSim']});

build/dev-cn_imapusersim.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

licenses/MIT.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
conjoon
2+
dev-cn_imapusersim
3+
Copyright (C) 2019 Thorsten Suckow-Homberg https://github.com/conjoon/dev-cn_imapusersim
4+
5+
Permission is hereby granted, free of charge, to any person
6+
obtaining a copy of this software and associated documentation
7+
files (the "Software"), to deal in the Software without restriction,
8+
including without limitation the rights to use, copy, modify, merge,
9+
publish, distribute, sublicense, and/or sell copies of the Software,
10+
and to permit persons to whom the Software is furnished to do so,
11+
subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22+
USE OR OTHER DEALINGS IN THE SOFTWARE.

licenses/Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# dev-cn_imapusersim/licenses
2+
3+
This folder contains the supported licenses for third-party use.

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
3+
"name": "dev-cn_imapusersim",
4+
5+
"sencha": {
6+
"namespace": "conjoon.dev.cn_imapusersim",
7+
"coon-js" : {"packageController" : true},
8+
"type": "code",
9+
"toolkit": "classic",
10+
"creator": "The conjoon Project - https://github.com/conjoon",
11+
"summary": "Sencha ExtJS Dev Package for mocking backend requests and data for conjoon/app-cn_imapuser.",
12+
"detailedDescription": "This package allows for mocking backend requests and helps while developing frontend code for conjoon/app-cn_imapuser.",
13+
"version": "1.0.0",
14+
"compatVersion": "1.0.0",
15+
"format": "1",
16+
"slicer": null,
17+
"fashion" : null,
18+
"output": {
19+
"base" : "${package.dir}/build",
20+
"js": {
21+
"version": "ES6"
22+
}
23+
},
24+
"compressor": {
25+
"polyfills": "none"
26+
},
27+
"local": true,
28+
"sass" : null,
29+
"classpath": [
30+
"${package.dir}/src"
31+
],
32+
"overrides": null,
33+
"example": null,
34+
"framework": "ext",
35+
"requires": [
36+
"lib-cn_core",
37+
"ux"
38+
]
39+
}
40+
}

src/Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# dev-cn_imapusersim/src
2+
3+
This folder contains source code that will automatically be added to the classpath when
4+
the package is used.

src/app/PackageController.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* conjoon
3+
* dev-cn_imapusersim
4+
* Copyright (C) 2019 Thorsten Suckow-Homberg https://github.com/conjoon/dev-cn_imapusersim
5+
*
6+
* Permission is hereby granted, free of charge, to any person
7+
* obtaining a copy of this software and associated documentation
8+
* files (the "Software"), to deal in the Software without restriction,
9+
* including without limitation the rights to use, copy, modify, merge,
10+
* publish, distribute, sublicense, and/or sell copies of the Software,
11+
* and to permit persons to whom the Software is furnished to do so,
12+
* subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included
15+
* in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23+
* USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
/**
27+
* PackageController for the dev-cn_imapusersim package.
28+
* Simply tags this package to make sure it can be loaded into a coon.js-Application.
29+
* Requires PackageSim and makes sure mocks are registered.
30+
*/
31+
Ext.define('conjoon.dev.cn_imapusersim.app.PackageController', {
32+
33+
extend : 'coon.core.app.PackageController',
34+
35+
requires : [
36+
'conjoon.dev.cn_imapusersim.data.imapuser.PackageSim'
37+
]
38+
39+
});

0 commit comments

Comments
 (0)