github.com/elliott5/community@v0.14.1-0.20160709191136-823126fb026a/app/mirage/config.js (about)

     1  import Mirage from 'ember-cli-mirage';
     2  
     3  export default function () {
     4  
     5  	this.passthrough('https://widget.intercom.io/widget/%7Bapp_id%7D');
     6  	this.urlPrefix = 'https://localhost:5001'; // make this `http://localhost:8080`, for example, if your API is on a different server
     7  	this.namespace = 'api'; // make this `api`, for example, if your API is namespaced
     8  	// this.timing = 400;      // delay for each request, automatically set to 0 during testing
     9  
    10  	this.logging = true;
    11  
    12  	this.get('/public/meta', function (schema) {
    13  		return schema.db.meta[0];
    14  	});
    15  
    16  	this.get('/public/validate', function (schema, request) {
    17  		let serverToken = request.queryParams.token;
    18  		let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0";
    19  
    20  		if (token = serverToken) {
    21  			return {
    22  				"id": "VzMuyEw_3WqiafcE",
    23  				"created": "2016-05-11T15:08:24Z",
    24  				"revised": "2016-05-11T15:08:24Z",
    25  				"firstname": "Lennex",
    26  				"lastname": "Zinyando",
    27  				"email": "brizdigital@gmail.com",
    28  				"initials": "LZ",
    29  				"active": true,
    30  				"editor": true,
    31  				"admin": true,
    32  				"accounts": [{
    33  					"id": "VzMuyEw_3WqiafcF",
    34  					"created": "2016-05-11T15:08:24Z",
    35  					"revised": "2016-05-11T15:08:24Z",
    36  					"admin": true,
    37  					"editor": true,
    38  					"userId": "VzMuyEw_3WqiafcE",
    39  					"orgId": "VzMuyEw_3WqiafcD",
    40  					"company": "EmberSherpa",
    41  					"title": "EmberSherpa",
    42  					"message": "This Documize instance contains all our team documentation",
    43  					"domain": ""
    44  				}]
    45  			};
    46  		}
    47  	});
    48  
    49  	this.get('/users/0/permissions', function () {
    50  		return [{
    51  			"folderId": "VzMygEw_3WrtFzto",
    52  			"userId": "",
    53  			"canView": true,
    54  			"canEdit": false
    55  		}];
    56  	});
    57  
    58  	this.get('/templates', function () {
    59  		return [];
    60  	});
    61  
    62  	this.get('/documents', function (schema, request) {
    63  		let folder_id = request.queryParams.folder;
    64  
    65  		if (folder_id = "VzMuyEw_3WqiafcG") {
    66  			return [{
    67  				"id": "VzMwX0w_3WrtFztd",
    68  				"created": "2016-05-11T13:15:11Z",
    69  				"revised": "2016-05-11T13:22:16Z",
    70  				"orgId": "VzMuyEw_3WqiafcD",
    71  				"folderId": "VzMuyEw_3WqiafcG",
    72  				"userId": "VzMuyEw_3WqiafcE",
    73  				"job": "",
    74  				"location": "template-0",
    75  				"name": "Empty Document",
    76  				"excerpt": "My test document",
    77  				"tags": "",
    78  				"template": false
    79  			}, {
    80  				"id": "VzMvJEw_3WqiafcI",
    81  				"created": "2016-05-11T13:09:56Z",
    82  				"revised": "2016-05-11T13:09:56Z",
    83  				"orgId": "VzMuyEw_3WqiafcD",
    84  				"folderId": "VzMuyEw_3WqiafcG",
    85  				"userId": "VzMuyEw_3WqiafcE",
    86  				"job": "0bf9b076-cb74-4e8e-75be-8ee2d24a8171",
    87  				"location": "/var/folders/d6/kr81d2fs5bsbm8rz2p092fy80000gn/T/documize/_uploads/0bf9b076-cb74-4e8e-75be-8ee2d24a8171/README.md",
    88  				"name": "README",
    89  				"excerpt": "To Document/ Instructions. GO. go- bindata- assetsfs. SSL.",
    90  				"tags": "",
    91  				"template": false
    92  			}];
    93  		} else if (folder_id = "VzMygEw_3WrtFzto") {
    94  			return {
    95  				"id": "VzMygEw_3WrtFzto",
    96  				"created": "2016-05-11T13:24:17Z",
    97  				"revised": "2016-05-11T13:25:51Z",
    98  				"name": "Test",
    99  				"orgId": "VzMuyEw_3WqiafcD",
   100  				"userId": "VzMuyEw_3WqiafcE",
   101  				"folderType": 1
   102  			};
   103  		} else if (folder_id = 'V0Vy5Uw_3QeDAMW9') {
   104  			return null;
   105  		}
   106  	});
   107  
   108  	this.get('/folders', function (schema) {
   109  		return schema.db.folders;
   110  	});
   111  
   112  	this.post('/folders', function (schema, request) {
   113  		var name = JSON.parse(request.requestBody).name;
   114  		let newFolder = {
   115  			"id": "V0Vy5Uw_3QeDAMW9",
   116  			"created": "2016-05-25T09:39:49Z",
   117  			"revised": "2016-05-25T09:39:49Z",
   118  			"name": name,
   119  			"orgId": "VzMuyEw_3WqiafcD",
   120  			"userId": "VzMuyEw_3WqiafcE",
   121  			"folderType": 2
   122  		};
   123  
   124  		let folder = schema.db.folders.insert(newFolder);
   125  		return folder;
   126  	});
   127  
   128  	this.post('/public/authenticate', (schema, request) => {
   129  		let authorization = request.requestHeaders.Authorization;
   130  		let expectedAuthorization = "Basic OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw==";
   131  
   132  		if (expectedAuthorization === authorization) {
   133  			console.log("SSO login success");
   134  			return {
   135  				"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
   136  				"user": {
   137  					"id": "VzMuyEw_3WqiafcE",
   138  					"created": "2016-05-11T15:08:24Z",
   139  					"revised": "2016-05-11T15:08:24Z",
   140  					"firstname": "Lennex",
   141  					"lastname": "Zinyando",
   142  					"email": "brizdigital@gmail.com",
   143  					"initials": "LZ",
   144  					"active": true,
   145  					"editor": true,
   146  					"admin": true,
   147  					"accounts": [{
   148  						"id": "VzMuyEw_3WqiafcF",
   149  						"created": "2016-05-11T15:08:24Z",
   150  						"revised": "2016-05-11T15:08:24Z",
   151  						"admin": true,
   152  						"editor": true,
   153  						"userId": "VzMuyEw_3WqiafcE",
   154  						"orgId": "VzMuyEw_3WqiafcD",
   155  						"company": "EmberSherpa",
   156  						"title": "EmberSherpa",
   157  						"message": "This Documize instance contains all our team documentation",
   158  						"domain": ""
   159  					}]
   160  				}
   161  			};
   162  		}
   163  
   164  		if (expectedAuthorization !== authorization) {
   165  			return new Mirage.Response(401, { 'Content-Type': 'application/json' }, { message: 'Bad Request' });
   166  		}
   167  
   168  		return {
   169  			"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
   170  			"user": {
   171  				"id": "VzMuyEw_3WqiafcE",
   172  				"created": "2016-05-11T15:08:24Z",
   173  				"revised": "2016-05-11T15:08:24Z",
   174  				"firstname": "Lennex",
   175  				"lastname": "Zinyando",
   176  				"email": "brizdigital@gmail.com",
   177  				"initials": "LZ",
   178  				"active": true,
   179  				"editor": true,
   180  				"admin": true,
   181  				"accounts": [{
   182  					"id": "VzMuyEw_3WqiafcF",
   183  					"created": "2016-05-11T15:08:24Z",
   184  					"revised": "2016-05-11T15:08:24Z",
   185  					"admin": true,
   186  					"editor": true,
   187  					"userId": "VzMuyEw_3WqiafcE",
   188  					"orgId": "VzMuyEw_3WqiafcD",
   189  					"company": "EmberSherpa",
   190  					"title": "EmberSherpa",
   191  					"message": "This Documize instance contains all our team documentation",
   192  					"domain": ""
   193  				}]
   194  			}
   195  		};
   196  
   197  	});
   198  
   199  	this.get('/users/VzMuyEw_3WqiafcE/permissions', (schema) => {
   200  		return schema.db.permissions;
   201  	});
   202  
   203  	this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => {
   204  		return [{
   205  			"folderId": "VzMuyEw_3WqiafcG",
   206  			"userId": "VzMuyEw_3WqiafcE",
   207  			"canView": true,
   208  			"canEdit": true
   209  		}];
   210  	});
   211  
   212  	this.put('/folders/VzMygEw_3WrtFzto/permissions', () => {
   213  		return [{
   214  			"orgId": "VzMuyEw_3WqiafcD",
   215  			"folderId": "VzMygEw_3WrtFzto",
   216  			"userId": "",
   217  			"canEdit": true,
   218  			"canView": true
   219  		}, {
   220  			"orgId": "VzMuyEw_3WqiafcD",
   221  			"folderId": "VzMygEw_3WrtFzto",
   222  			"userId": "VzMyp0w_3WrtFztq",
   223  			"canEdit": false,
   224  			"canView": false
   225  		}, {
   226  			"orgId": "",
   227  			"folderId": "VzMygEw_3WrtFzto",
   228  			"userId": "VzMuyEw_3WqiafcE",
   229  			"canEdit": true,
   230  			"canView": true
   231  		}];
   232  	});
   233  
   234  	this.get('/folders/VzMygEw_3WrtFzto/permissions', () => {
   235  		return [{
   236  			"folderId": "VzMygEw_3WrtFzto",
   237  			"userId": "VzMuyEw_3WqiafcE",
   238  			"canView": true,
   239  			"canEdit": true
   240  		}];
   241  	});
   242  
   243  	this.put('/folders/:id', (schema, request) => {
   244  		let id = request.params.id;
   245  		let attrs = JSON.parse(request.requestBody);
   246  		let folder = schema.db.folders.update(id, attrs);
   247  		return folder;
   248  	});
   249  
   250  	this.put('/folders/V0Vy5Uw_3QeDAMW9', () => {
   251  		return {
   252  			"id": "V0Vy5Uw_3QeDAMW9",
   253  			"created": "2016-05-25T09:39:49Z",
   254  			"revised": "2016-05-25T09:39:49Z",
   255  			"name": "Test Folder",
   256  			"orgId": "VzMuyEw_3WqiafcD",
   257  			"userId": "VzMuyEw_3WqiafcE",
   258  			"folderType": 2
   259  		};
   260  	});
   261  
   262  	this.get('folders/:id', (schema, request) => {
   263  		let id = request.params.id;
   264  		return schema.db.folders.find(id);
   265  	});
   266  
   267  	this.get('/organizations/VzMuyEw_3WqiafcD', () => {
   268  		return {
   269  			"id": "VzMuyEw_3WqiafcD",
   270  			"created": "2016-05-11T15:08:24Z",
   271  			"revised": "2016-05-23T11:23:20Z",
   272  			"title": "EmberSherpa",
   273  			"message": "This Documize instance contains all our team documentation",
   274  			"url": "",
   275  			"domain": "",
   276  			"email": "brizdigital@gmail.com",
   277  			"allowAnonymousAccess": false
   278  		};
   279  	});
   280  
   281  	this.put('/organizations/VzMuyEw_3WqiafcD', (schema, request) => {
   282  		let title = JSON.parse(request.requestBody).title;
   283  		let message = JSON.parse(request.requestBody).title;
   284  		let allowAnonymousAccess = JSON.parse(request.requestBody).allowAnonymousAccess;
   285  
   286  		return {
   287  			"id": "VzMuyEw_3WqiafcD",
   288  			"created": "2016-05-11T15:08:24Z",
   289  			"revised": "2016-05-23T11:23:20Z",
   290  			"title": `${title}`,
   291  			"message": `${message}`,
   292  			"url": "",
   293  			"domain": "",
   294  			"email": "brizdigital@gmail.com",
   295  			"allowAnonymousAccess": `${allowAnonymousAccess}`
   296  		};
   297  	});
   298  
   299  	this.get('/users', () => {
   300  		return [{
   301  			"id": "VzMyp0w_3WrtFztq",
   302  			"created": "2016-05-11T13:24:55Z",
   303  			"revised": "2016-05-11T13:33:47Z",
   304  			"firstname": "Len",
   305  			"lastname": "Random",
   306  			"email": "zinyando@gmail.com",
   307  			"initials": "LR",
   308  			"active": true,
   309  			"editor": true,
   310  			"admin": false,
   311  			"accounts": [{
   312  				"id": "VzMyp0w_3WrtFztr",
   313  				"created": "2016-05-11T13:24:55Z",
   314  				"revised": "2016-05-11T13:24:55Z",
   315  				"admin": false,
   316  				"editor": true,
   317  				"userId": "VzMyp0w_3WrtFztq",
   318  				"orgId": "VzMuyEw_3WqiafcD",
   319  				"company": "EmberSherpa",
   320  				"title": "EmberSherpa",
   321  				"message": "This Documize instance contains all our team documentation",
   322  				"domain": ""
   323  			}]
   324  		}, {
   325  			"id": "VzMuyEw_3WqiafcE",
   326  			"created": "2016-05-11T15:08:24Z",
   327  			"revised": "2016-05-11T15:08:24Z",
   328  			"firstname": "Lennex",
   329  			"lastname": "Zinyando",
   330  			"email": "brizdigital@gmail.com",
   331  			"initials": "LZ",
   332  			"active": true,
   333  			"editor": true,
   334  			"admin": true,
   335  			"accounts": [{
   336  				"id": "VzMuyEw_3WqiafcF",
   337  				"created": "2016-05-11T15:08:24Z",
   338  				"revised": "2016-05-11T15:08:24Z",
   339  				"admin": true,
   340  				"editor": true,
   341  				"userId": "VzMuyEw_3WqiafcE",
   342  				"orgId": "VzMuyEw_3WqiafcD",
   343  				"company": "EmberSherpa",
   344  				"title": "EmberSherpa",
   345  				"message": "This Documize instance contains all our team documentation",
   346  				"domain": ""
   347  			}]
   348  		}];
   349  	});
   350  
   351  	this.post('/users', (schema, request) => {
   352  		let firstname = JSON.parse(request.requestBody).firstname;
   353  		let lastname = JSON.parse(request.requestBody).lastname;
   354  		let email = JSON.parse(request.requestBody).email;
   355  
   356  		return {
   357  			"id": "V0RmtUw_3QeDAMW7",
   358  			"created": "2016-05-24T14:35:33Z",
   359  			"revised": "2016-05-24T14:35:33Z",
   360  			"firstname": `${firstname}`,
   361  			"lastname": `${lastname}`,
   362  			"email": `${email}`,
   363  			"initials": "TU",
   364  			"active": true,
   365  			"editor": true,
   366  			"admin": false,
   367  			"accounts": [{
   368  				"id": "V0RmtUw_3QeDAMW8",
   369  				"created": "2016-05-24T14:35:34Z",
   370  				"revised": "2016-05-24T14:35:34Z",
   371  				"admin": false,
   372  				"editor": true,
   373  				"userId": "V0RmtUw_3QeDAMW7",
   374  				"orgId": "VzMuyEw_3WqiafcD",
   375  				"company": "EmberSherpa",
   376  				"title": "EmberSherpa",
   377  				"message": "This Documize instance contains all our team documentation",
   378  				"domain": ""
   379  			}]
   380  		};
   381  	});
   382  
   383  	this.get('/users/VzMuyEw_3WqiafcE', () => {
   384  
   385  		return {
   386  			"id": "VzMuyEw_3WqiafcE",
   387  			"created": "2016-05-11T15:08:24Z",
   388  			"revised": "2016-05-11T15:08:24Z",
   389  			"firstname": "Lennex",
   390  			"lastname": "Zinyando",
   391  			"email": "brizdigital@gmail.com",
   392  			"initials": "LZ",
   393  			"active": true,
   394  			"editor": true,
   395  			"admin": true,
   396  			"accounts": [{
   397  				"id": "VzMuyEw_3WqiafcF",
   398  				"created": "2016-05-11T15:08:24Z",
   399  				"revised": "2016-05-11T15:08:24Z",
   400  				"admin": true,
   401  				"editor": true,
   402  				"userId": "VzMuyEw_3WqiafcE",
   403  				"orgId": "VzMuyEw_3WqiafcD",
   404  				"company": "EmberSherpa",
   405  				"title": "EmberSherpa",
   406  				"message": "This Documize instance contains all our team documentation",
   407  				"domain": ""
   408  			}]
   409  		};
   410  	});
   411  
   412  	this.put('/users/VzMuyEw_3WqiafcE', (schema, request) => {
   413  		let firstname = JSON.parse(request.requestBody).firstname;
   414  		let lastname = JSON.parse(request.requestBody).lastname;
   415  		let email = JSON.parse(request.requestBody).email;
   416  
   417  		return {
   418  			"id": "VzMuyEw_3WqiafcE",
   419  			"created": "2016-05-11T15:08:24Z",
   420  			"revised": "2016-05-11T15:08:24Z",
   421  			"firstname": `${firstname}`,
   422  			"lastname": `${lastname}`,
   423  			"email": `${email}`,
   424  			"initials": "LZ",
   425  			"active": true,
   426  			"editor": true,
   427  			"admin": true,
   428  			"accounts": [{
   429  				"id": "VzMuyEw_3WqiafcF",
   430  				"created": "2016-05-11T15:08:24Z",
   431  				"revised": "2016-05-11T15:08:24Z",
   432  				"admin": true,
   433  				"editor": true,
   434  				"userId": "VzMuyEw_3WqiafcE",
   435  				"orgId": "VzMuyEw_3WqiafcD",
   436  				"company": "EmberSherpa",
   437  				"title": "EmberSherpa",
   438  				"message": "This Documize instance contains all our team documentation",
   439  				"domain": ""
   440  			}]
   441  		};
   442  	});
   443  
   444  	this.post('/folders/VzMuyEw_3WqiafcG/invitation', () => {
   445  		return {};
   446  	});
   447  
   448  }