Best JavaScript code snippet using cypress
authorize-handler_test.js
Source:authorize-handler_test.js
...40 e.should.be.an.instanceOf(InvalidArgumentError);41 e.message.should.equal('Missing parameter: `model`');42 }43 });44 it('should throw an error if the model does not implement `getClient()`', function() {45 try {46 new AuthorizeHandler({ authorizationCodeLifetime: 120, model: {} });47 should.fail();48 } catch (e) {49 e.should.be.an.instanceOf(InvalidArgumentError);50 e.message.should.equal('Invalid argument: model does not implement `getClient()`');51 }52 });53 it('should throw an error if the model does not implement `saveAuthorizationCode()`', function() {54 try {55 new AuthorizeHandler({ authorizationCodeLifetime: 120, model: { getClient: function() {} } });56 should.fail();57 } catch (e) {58 e.should.be.an.instanceOf(InvalidArgumentError);59 e.message.should.equal('Invalid argument: model does not implement `saveAuthorizationCode()`');60 }61 });62 it('should throw an error if the model does not implement `getAccessToken()`', function() {63 var model = {64 getClient: function() {},65 saveAuthorizationCode: function() {}66 };67 try {68 new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });69 should.fail();70 } catch (e) {71 e.should.be.an.instanceOf(InvalidArgumentError);72 e.message.should.equal('Invalid argument: model does not implement `getAccessToken()`');73 }74 });75 it('should set the `authorizationCodeLifetime`', function() {76 var model = {77 getAccessToken: function() {},78 getClient: function() {},79 saveAuthorizationCode: function() {}80 };81 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });82 handler.authorizationCodeLifetime.should.equal(120);83 });84 it('should set the `authenticateHandler`', function() {85 var model = {86 getAccessToken: function() {},87 getClient: function() {},88 saveAuthorizationCode: function() {}89 };90 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });91 handler.authenticateHandler.should.be.an.instanceOf(AuthenticateHandler);92 });93 it('should set the `model`', function() {94 var model = {95 getAccessToken: function() {},96 getClient: function() {},97 saveAuthorizationCode: function() {}98 };99 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });100 handler.model.should.equal(model);101 });102 });103 describe('handle()', function() {104 it('should throw an error if `request` is missing', function() {105 var model = {106 getAccessToken: function() {},107 getClient: function() {},108 saveAuthorizationCode: function() {}109 };110 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });111 try {112 handler.handle();113 should.fail();114 } catch (e) {115 e.should.be.an.instanceOf(InvalidArgumentError);116 e.message.should.equal('Invalid argument: `request` must be an instance of Request');117 }118 });119 it('should throw an error if `response` is missing', function() {120 var model = {121 getAccessToken: function() {},122 getClient: function() {},123 saveAuthorizationCode: function() {}124 };125 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });126 var request = new Request({ body: {}, headers: {}, method: {}, query: {} });127 try {128 handler.handle(request);129 should.fail();130 } catch (e) {131 e.should.be.an.instanceOf(InvalidArgumentError);132 e.message.should.equal('Invalid argument: `response` must be an instance of Response');133 }134 });135 it('should throw an error if `allowed` is `false`', function() {136 var model = {137 getAccessToken: function() {},138 getClient: function() {},139 saveAuthorizationCode: function() {}140 };141 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });142 var request = new Request({ body: {}, headers: {}, method: {}, query: { allowed: 'false' } });143 var response = new Response({ body: {}, headers: {} });144 return handler.handle(request, response)145 .then(should.fail)146 .catch(function(e) {147 e.should.be.an.instanceOf(AccessDeniedError);148 e.message.should.equal('Access denied: user denied access to application');149 });150 });151 it('should redirect to an error response if a non-oauth error is thrown', function() {152 var model = {153 getAccessToken: function() {154 return {155 user: {},156 accessTokenExpiresAt: new Date(new Date().getTime() + 10000)157 };158 },159 getClient: function() {160 return { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };161 },162 saveAuthorizationCode: function() {163 throw new Error('Unhandled exception');164 }165 };166 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });167 var request = new Request({168 body: {169 client_id: 12345,170 response_type: 'code'171 },172 headers: {173 'Authorization': 'Bearer foo'174 },175 method: {},176 query: {177 state: 'foobar'178 }179 });180 var response = new Response({ body: {}, headers: {} });181 return handler.handle(request, response)182 .then(should.fail)183 .catch(function() {184 response.get('location').should.equal('http://example.com/cb?error=server_error&error_description=Unhandled%20exception&state=foobar');185 });186 });187 it('should redirect to an error response if an oauth error is thrown', function() {188 var model = {189 getAccessToken: function() {190 return {191 user: {},192 accessTokenExpiresAt: new Date(new Date().getTime() + 10000)193 };194 },195 getClient: function() {196 return { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };197 },198 saveAuthorizationCode: function() {199 throw new AccessDeniedError('Cannot request this auth code');200 }201 };202 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });203 var request = new Request({204 body: {205 client_id: 12345,206 response_type: 'code'207 },208 headers: {209 'Authorization': 'Bearer foo'210 },211 method: {},212 query: {213 state: 'foobar'214 }215 });216 var response = new Response({ body: {}, headers: {} });217 return handler.handle(request, response)218 .then(should.fail)219 .catch(function() {220 response.get('location').should.equal('http://example.com/cb?error=access_denied&error_description=Cannot%20request%20this%20auth%20code&state=foobar');221 });222 });223 it('should redirect to a successful response with `code` and `state` if successful', function() {224 var client = { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };225 var model = {226 getAccessToken: function() {227 return {228 client: client,229 user: {},230 accessTokenExpiresAt: new Date(new Date().getTime() + 10000)231 };232 },233 getClient: function() {234 return client;235 },236 saveAuthorizationCode: function() {237 return { authorizationCode: 12345, client: client };238 }239 };240 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });241 var request = new Request({242 body: {243 client_id: 12345,244 response_type: 'code'245 },246 headers: {247 'Authorization': 'Bearer foo'248 },249 method: {},250 query: {251 state: 'foobar'252 }253 });254 var response = new Response({ body: {}, headers: {} });255 return handler.handle(request, response)256 .then(function() {257 response.get('location').should.equal('http://example.com/cb?code=12345&state=foobar');258 })259 .catch(should.fail);260 });261 it('should redirect to an error response if `scope` is invalid', function() {262 var model = {263 getAccessToken: function() {264 return {265 user: {},266 accessTokenExpiresAt: new Date(new Date().getTime() + 10000)267 };268 },269 getClient: function() {270 return { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };271 },272 saveAuthorizationCode: function() {273 return {};274 }275 };276 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });277 var request = new Request({278 body: {279 client_id: 12345,280 response_type: 'code'281 },282 headers: {283 'Authorization': 'Bearer foo'284 },285 method: {},286 query: {287 scope: [],288 state: 'foobar'289 }290 });291 var response = new Response({ body: {}, headers: {} });292 return handler.handle(request, response)293 .then(should.fail)294 .catch(function() {295 response.get('location').should.equal('http://example.com/cb?error=invalid_scope&error_description=Invalid%20parameter%3A%20%60scope%60');296 });297 });298 it('should redirect to a successful response if `model.validateScope` is not defined', function() {299 var client = { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };300 var model = {301 getAccessToken: function() {302 return {303 client: client,304 user: {},305 accessTokenExpiresAt: new Date(new Date().getTime() + 10000)306 };307 },308 getClient: function() {309 return client;310 },311 saveAuthorizationCode: function() {312 return { authorizationCode: 12345, client: client };313 }314 };315 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });316 var request = new Request({317 body: {318 client_id: 12345,319 response_type: 'code'320 },321 headers: {322 'Authorization': 'Bearer foo'323 },324 method: {},325 query: {326 scope: 'read',327 state: 'foobar'328 }329 });330 var response = new Response({ body: {}, headers: {} });331 return handler.handle(request, response)332 .then(function(data) {333 data.should.eql({334 authorizationCode: 12345,335 client: client336 });337 })338 .catch(should.fail);339 });340 it('should redirect to an error response if `scope` is insufficient', function() {341 var client = { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };342 var model = {343 getAccessToken: function() {344 return {345 client: client,346 user: {},347 accessTokenExpiresAt: new Date(new Date().getTime() + 10000)348 };349 },350 getClient: function() {351 return client;352 },353 saveAuthorizationCode: function() {354 return { authorizationCode: 12345, client: client };355 },356 validateScope: function() {357 return false;358 }359 };360 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });361 var request = new Request({362 body: {363 client_id: 12345,364 response_type: 'code'365 },366 headers: {367 'Authorization': 'Bearer foo'368 },369 method: {},370 query: {371 scope: 'read',372 state: 'foobar'373 }374 });375 var response = new Response({ body: {}, headers: {} });376 return handler.handle(request, response)377 .then(should.fail)378 .catch(function() {379 response.get('location').should.equal('http://example.com/cb?error=invalid_scope&error_description=Invalid%20scope%3A%20Requested%20scope%20is%20invalid');380 });381 });382 it('should redirect to an error response if `state` is missing', function() {383 var model = {384 getAccessToken: function() {385 return {386 user: {},387 accessTokenExpiresAt: new Date(new Date().getTime() + 10000)388 };389 },390 getClient: function() {391 return { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };392 },393 saveAuthorizationCode: function() {394 throw new AccessDeniedError('Cannot request this auth code');395 }396 };397 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });398 var request = new Request({399 body: {400 client_id: 12345,401 response_type: 'code'402 },403 headers: {404 'Authorization': 'Bearer foo'405 },406 method: {},407 query: {}408 });409 var response = new Response({ body: {}, headers: {} });410 return handler.handle(request, response)411 .then(should.fail)412 .catch(function() {413 response.get('location').should.equal('http://example.com/cb?error=invalid_request&error_description=Missing%20parameter%3A%20%60state%60');414 });415 });416 it('should redirect to an error response if `response_type` is invalid', function() {417 var model = {418 getAccessToken: function() {419 return {420 user: {},421 accessTokenExpiresAt: new Date(new Date().getTime() + 10000)422 };423 },424 getClient: function() {425 return { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };426 },427 saveAuthorizationCode: function() {428 return { authorizationCode: 12345, client: {} };429 }430 };431 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });432 var request = new Request({433 body: {434 client_id: 12345,435 response_type: 'test'436 },437 headers: {438 'Authorization': 'Bearer foo'439 },440 method: {},441 query: {442 state: 'foobar'443 }444 });445 var response = new Response({ body: {}, headers: {} });446 return handler.handle(request, response)447 .then(should.fail)448 .catch(function() {449 response.get('location').should.equal('http://example.com/cb?error=unsupported_response_type&error_description=Unsupported%20response%20type%3A%20%60response_type%60%20is%20not%20supported&state=foobar');450 });451 });452 it('should fail on invalid `response_type` before calling model.saveAuthorizationCode()', function() {453 var model = {454 getAccessToken: function() {455 return {456 user: {},457 accessTokenExpiresAt: new Date(new Date().getTime() + 10000)458 };459 },460 getClient: function() {461 return { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };462 },463 saveAuthorizationCode: function() {464 throw new Error('must not be reached');465 }466 };467 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });468 var request = new Request({469 body: {470 client_id: 12345,471 response_type: 'test'472 },473 headers: {474 'Authorization': 'Bearer foo'475 },476 method: {},477 query: {478 state: 'foobar'479 }480 });481 var response = new Response({ body: {}, headers: {} });482 return handler.handle(request, response)483 .then(should.fail)484 .catch(function() {485 response.get('location').should.equal('http://example.com/cb?error=unsupported_response_type&error_description=Unsupported%20response%20type%3A%20%60response_type%60%20is%20not%20supported&state=foobar');486 });487 });488 it('should return the `code` if successful with extend model obj with request', function() {489 var client = { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };490 var model = {491 getAccessToken: function() {492 return {493 client: client,494 user: {},495 accessTokenExpiresAt: new Date(new Date().getTime() + 10000)496 };497 },498 getClient: function() {499 return client;500 },501 saveAuthorizationCode: function() {502 return { authorizationCode: 12345, client: client };503 }504 };505 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });506 var request = new Request({507 body: {508 client_id: 12345,509 response_type: 'code'510 },511 headers: {512 'Authorization': 'Bearer foo'513 },514 method: {},515 query: {516 state: 'foobar'517 }518 });519 var response = new Response({ body: {}, headers: {} });520 return handler.handle(request, response)521 .then(function(data) {522 model.request.should.equal(request);523 data.should.eql({524 authorizationCode: 12345,525 client: client526 });527 })528 .catch(should.fail);529 });530 });531 describe('generateAuthorizationCode()', function() {532 it('should return an auth code', function() {533 var model = {534 getAccessToken: function() {},535 getClient: function() {},536 saveAuthorizationCode: function() {}537 };538 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });539 return handler.generateAuthorizationCode()540 .then(function(data) {541 data.should.be.a.sha1;542 })543 .catch(should.fail);544 });545 it('should support promises', function() {546 var model = {547 generateAuthorizationCode: function() {548 return Promise.resolve({});549 },550 getAccessToken: function() {},551 getClient: function() {},552 saveAuthorizationCode: function() {}553 };554 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });555 handler.generateAuthorizationCode().should.be.an.instanceOf(Promise);556 });557 it('should support non-promises', function() {558 var model = {559 generateAuthorizationCode: function() {560 return {};561 },562 getAccessToken: function() {},563 getClient: function() {},564 saveAuthorizationCode: function() {}565 };566 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });567 handler.generateAuthorizationCode().should.be.an.instanceOf(Promise);568 });569 });570 describe('getAuthorizationCodeLifetime()', function() {571 it('should return a date', function() {572 var model = {573 getAccessToken: function() {},574 getClient: function() {},575 saveAuthorizationCode: function() {}576 };577 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });578 handler.getAuthorizationCodeLifetime().should.be.an.instanceOf(Date);579 });580 });581 describe('getClient()', function() {582 it('should throw an error if `client_id` is missing', function() {583 var model = {584 getAccessToken: function() {},585 getClient: function() {},586 saveAuthorizationCode: function() {}587 };588 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });589 var request = new Request({ body: { response_type: 'code' }, headers: {}, method: {}, query: {} });590 try {591 handler.getClient(request);592 should.fail();593 } catch (e) {594 e.should.be.an.instanceOf(InvalidRequestError);595 e.message.should.equal('Missing parameter: `client_id`');596 }597 });598 it('should throw an error if `client_id` is invalid', function() {599 var model = {600 getAccessToken: function() {},601 getClient: function() {},602 saveAuthorizationCode: function() {}603 };604 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });605 var request = new Request({ body: { client_id: 'øåâ¬Â£â°', response_type: 'code' }, headers: {}, method: {}, query: {} });606 try {607 handler.getClient(request);608 should.fail();609 } catch (e) {610 e.should.be.an.instanceOf(InvalidRequestError);611 e.message.should.equal('Invalid parameter: `client_id`');612 }613 });614 it('should throw an error if `client.redirectUri` is invalid', function() {615 var model = {616 getAccessToken: function() {},617 getClient: function() {},618 saveAuthorizationCode: function() {}619 };620 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });621 var request = new Request({ body: { client_id: 12345, response_type: 'code', redirect_uri: 'foobar' }, headers: {}, method: {}, query: {} });622 try {623 handler.getClient(request);624 should.fail();625 } catch (e) {626 e.should.be.an.instanceOf(InvalidRequestError);627 e.message.should.equal('Invalid request: `redirect_uri` is not a valid URI');628 }629 });630 it('should throw an error if `client` is missing', function() {631 var model = {632 getAccessToken: function() {},633 getClient: function() {},634 saveAuthorizationCode: function() {}635 };636 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });637 var request = new Request({ body: { client_id: 12345, response_type: 'code' }, headers: {}, method: {}, query: {} });638 return handler.getClient(request)639 .then(should.fail)640 .catch(function(e) {641 e.should.be.an.instanceOf(InvalidClientError);642 e.message.should.equal('Invalid client: client credentials are invalid');643 });644 });645 it('should throw an error if `client.grants` is missing', function() {646 var model = {647 getAccessToken: function() {},648 getClient: function() {649 return {};650 },651 saveAuthorizationCode: function() {}652 };653 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });654 var request = new Request({ body: { client_id: 12345, response_type: 'code' }, headers: {}, method: {}, query: {} });655 return handler.getClient(request)656 .then(should.fail)657 .catch(function(e) {658 e.should.be.an.instanceOf(InvalidClientError);659 e.message.should.equal('Invalid client: missing client `grants`');660 });661 });662 it('should throw an error if `client` is unauthorized', function() {663 var model = {664 getAccessToken: function() {},665 getClient: function() {666 return { grants: [] };667 },668 saveAuthorizationCode: function() {}669 };670 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });671 var request = new Request({ body: { client_id: 12345, response_type: 'code' }, headers: {}, method: {}, query: {} });672 return handler.getClient(request)673 .then(should.fail)674 .catch(function(e) {675 e.should.be.an.instanceOf(UnauthorizedClientError);676 e.message.should.equal('Unauthorized client: `grant_type` is invalid');677 });678 });679 it('should throw an error if `client.redirectUri` is missing', function() {680 var model = {681 getAccessToken: function() {},682 getClient: function() { return { grants: ['authorization_code'] }; },683 saveAuthorizationCode: function() {}684 };685 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });686 var request = new Request({ body: { client_id: 12345, response_type: 'code' }, headers: {}, method: {}, query: {} });687 return handler.getClient(request)688 .then(should.fail)689 .catch(function(e) {690 e.should.be.an.instanceOf(InvalidClientError);691 e.message.should.equal('Invalid client: missing client `redirectUri`');692 });693 });694 it('should throw an error if `client.redirectUri` is not equal to `redirectUri`', function() {695 var model = {696 getAccessToken: function() {},697 getClient: function() {698 return { grants: ['authorization_code'], redirectUris: ['https://example.com'] };699 },700 saveAuthorizationCode: function() {}701 };702 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });703 var request = new Request({ body: { client_id: 12345, response_type: 'code', redirect_uri: 'https://foobar.com' }, headers: {}, method: {}, query: {} });704 return handler.getClient(request)705 .then(should.fail)706 .catch(function(e) {707 e.should.be.an.instanceOf(InvalidClientError);708 e.message.should.equal('Invalid client: `redirect_uri` does not match client value');709 });710 });711 it('should support promises', function() {712 var model = {713 getAccessToken: function() {},714 getClient: function() {715 return Promise.resolve({ grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] });716 },717 saveAuthorizationCode: function() {}718 };719 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });720 var request = new Request({721 body: { client_id: 12345 },722 headers: {},723 method: {},724 query: {}725 });726 handler.getClient(request).should.be.an.instanceOf(Promise);727 });728 it('should support non-promises', function() {729 var model = {730 getAccessToken: function() {},731 getClient: function() {732 return { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };733 },734 saveAuthorizationCode: function() {}735 };736 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });737 var request = new Request({738 body: { client_id: 12345 },739 headers: {},740 method: {},741 query: {}742 });743 handler.getClient(request).should.be.an.instanceOf(Promise);744 });745 it('should support callbacks', function() {746 var model = {747 getAccessToken: function() {},748 getClient: function(clientId, clientSecret, callback) {749 should.equal(clientSecret, null);750 callback(null, { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] });751 },752 saveAuthorizationCode: function() {}753 };754 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });755 var request = new Request({756 body: { client_id: 12345 },757 headers: {},758 method: {},759 query: {}760 });761 handler.getClient(request).should.be.an.instanceOf(Promise);762 });763 describe('with `client_id` in the request query', function() {764 it('should return a client', function() {765 var client = { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };766 var model = {767 getAccessToken: function() {},768 getClient: function() {769 return client;770 },771 saveAuthorizationCode: function() {}772 };773 var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });774 var request = new Request({ body: { response_type: 'code' }, headers: {}, method: {}, query: { client_id: 12345 } });775 return handler.getClient(request)776 .then(function(data) {777 data.should.equal(client);778 })779 .catch(should.fail);780 });781 });782 });783 describe('getScope()', function() {784 it('should throw an error if `scope` is invalid', function() {785 var model = {786 getAccessToken: function() {},787 getClient: function() {},788 saveAuthorizationCode: function() {}789 };...
token-handler_test.js
Source:token-handler_test.js
...49 e.should.be.an.instanceOf(InvalidArgumentError);50 e.message.should.equal('Missing parameter: `refreshTokenLifetime`');51 }52 });53 it('should throw an error if the model does not implement `getClient()`', function() {54 try {55 new TokenHandler({ accessTokenLifetime: 120, model: {}, refreshTokenLifetime: 120 });56 should.fail();57 } catch (e) {58 e.should.be.an.instanceOf(InvalidArgumentError);59 e.message.should.equal('Invalid argument: model does not implement `getClient()`');60 }61 });62 it('should set the `accessTokenLifetime`', function() {63 var accessTokenLifetime = {};64 var model = {65 getClient: function() {},66 saveToken: function() {}67 };68 var handler = new TokenHandler({ accessTokenLifetime: accessTokenLifetime, model: model, refreshTokenLifetime: 120 });69 handler.accessTokenLifetime.should.equal(accessTokenLifetime);70 });71 it('should set the `alwaysIssueNewRefreshToken`', function() {72 var alwaysIssueNewRefreshToken = true;73 var model = {74 getClient: function() {},75 saveToken: function() {}76 };77 var handler = new TokenHandler({ accessTokenLifetime: 123, model: model, refreshTokenLifetime: 120, alwaysIssueNewRefreshToken: alwaysIssueNewRefreshToken });78 handler.alwaysIssueNewRefreshToken.should.equal(alwaysIssueNewRefreshToken);79 });80 it('should set the `alwaysIssueNewRefreshToken` to false', function() {81 var alwaysIssueNewRefreshToken = false;82 var model = {83 getClient: function() {},84 saveToken: function() {}85 };86 var handler = new TokenHandler({ accessTokenLifetime: 123, model: model, refreshTokenLifetime: 120, alwaysIssueNewRefreshToken: alwaysIssueNewRefreshToken });87 handler.alwaysIssueNewRefreshToken.should.equal(alwaysIssueNewRefreshToken);88 });89 it('should return the default `alwaysIssueNewRefreshToken` value', function() {90 var model = {91 getClient: function() {},92 saveToken: function() {}93 };94 var handler = new TokenHandler({ accessTokenLifetime: 123, model: model, refreshTokenLifetime: 120 });95 handler.alwaysIssueNewRefreshToken.should.equal(true);96 });97 it('should set the `extendedGrantTypes`', function() {98 var extendedGrantTypes = { foo: 'bar' };99 var model = {100 getClient: function() {},101 saveToken: function() {}102 };103 var handler = new TokenHandler({ accessTokenLifetime: 120, extendedGrantTypes: extendedGrantTypes, model: model, refreshTokenLifetime: 120 });104 handler.grantTypes.should.containEql(extendedGrantTypes);105 });106 it('should set the `model`', function() {107 var model = {108 getClient: function() {},109 saveToken: function() {}110 };111 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });112 handler.model.should.equal(model);113 });114 it('should set the `refreshTokenLifetime`', function() {115 var refreshTokenLifetime = {};116 var model = {117 getClient: function() {},118 saveToken: function() {}119 };120 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: refreshTokenLifetime });121 handler.refreshTokenLifetime.should.equal(refreshTokenLifetime);122 });123 });124 describe('handle()', function() {125 it('should throw an error if `request` is missing', function() {126 var model = {127 getClient: function() {},128 saveToken: function() {}129 };130 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });131 try {132 handler.handle();133 should.fail();134 } catch (e) {135 e.should.be.an.instanceOf(InvalidArgumentError);136 e.message.should.equal('Invalid argument: `request` must be an instance of Request');137 }138 });139 it('should throw an error if `response` is missing', function() {140 var model = {141 getClient: function() {},142 saveToken: function() {}143 };144 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });145 var request = new Request({ body: {}, headers: {}, method: {}, query: {} });146 try {147 handler.handle(request);148 should.fail();149 } catch (e) {150 e.should.be.an.instanceOf(InvalidArgumentError);151 e.message.should.equal('Invalid argument: `response` must be an instance of Response');152 }153 });154 it('should throw an error if the method is not `POST`', function() {155 var model = {156 getClient: function() {},157 saveToken: function() {}158 };159 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });160 var request = new Request({ body: {}, headers: {}, method: 'GET', query: {} });161 var response = new Response({ body: {}, headers: {} });162 return handler.handle(request, response)163 .then(should.fail)164 .catch(function(e) {165 e.should.be.an.instanceOf(InvalidRequestError);166 e.message.should.equal('Invalid request: method must be POST');167 });168 });169 it('should throw an error if the media type is not `application/x-www-form-urlencoded`', function() {170 var model = {171 getClient: function() {},172 saveToken: function() {}173 };174 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });175 var request = new Request({ body: {}, headers: {}, method: 'POST', query: {} });176 var response = new Response({ body: {}, headers: {} });177 return handler.handle(request, response)178 .then(should.fail)179 .catch(function(e) {180 e.should.be.an.instanceOf(InvalidRequestError);181 e.message.should.equal('Invalid request: content must be application/x-www-form-urlencoded');182 });183 });184 it('should throw the error if an oauth error is thrown', function() {185 var model = {186 getClient: function() {},187 saveToken: function() {}188 };189 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });190 var request = new Request({ body: {}, headers: { 'content-type': 'application/x-www-form-urlencoded', 'transfer-encoding': 'chunked' }, method: 'POST', query: {} });191 var response = new Response({ body: {}, headers: {} });192 return handler.handle(request, response)193 .then(should.fail)194 .catch(function(e) {195 e.should.be.an.instanceOf(InvalidClientError);196 e.message.should.equal('Invalid client: cannot retrieve client credentials');197 });198 });199 it('should throw a server error if a non-oauth error is thrown', function() {200 var model = {201 getClient: function() {202 throw new Error('Unhandled exception');203 },204 getUser: function() {},205 saveToken: function() {}206 };207 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });208 var request = new Request({209 body: {210 client_id: 12345,211 client_secret: 'secret',212 grant_type: 'password',213 password: 'bar',214 username: 'foo'215 },216 headers: { 'content-type': 'application/x-www-form-urlencoded', 'transfer-encoding': 'chunked' },217 method: 'POST',218 query: {}219 });220 var response = new Response({ body: {}, headers: {} });221 return handler.handle(request, response)222 .then(should.fail)223 .catch(function(e) {224 e.should.be.an.instanceOf(ServerError);225 e.message.should.equal('Unhandled exception');226 e.inner.should.be.an.instanceOf(Error);227 });228 });229 it('should update the response if an error is thrown', function() {230 var model = {231 getClient: function() {232 throw new Error('Unhandled exception');233 },234 getUser: function() {},235 saveToken: function() {}236 };237 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });238 var request = new Request({239 body: {240 client_id: 12345,241 client_secret: 'secret',242 grant_type: 'password',243 password: 'bar',244 username: 'foo'245 },246 headers: { 'content-type': 'application/x-www-form-urlencoded', 'transfer-encoding': 'chunked' },247 method: 'POST',248 query: {}249 });250 var response = new Response({ body: {}, headers: {} });251 return handler.handle(request, response)252 .then(should.fail)253 .catch(function() {254 response.body.should.eql({ error: 'server_error', error_description: 'Unhandled exception' });255 response.status.should.equal(503);256 });257 });258 it('should return a bearer token if successful with extend model obj with request', function() {259 var token = { accessToken: 'foo', client: {}, refreshToken: 'bar', scope: 'foobar', user: {} };260 var model = {261 getClient: function() { return { grants: ['password'] }; },262 getUser: function() { return {}; },263 saveToken: function() { return token; },264 validateScope: function() { return 'baz'; }265 };266 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });267 var request = new Request({268 body: {269 client_id: 12345,270 client_secret: 'secret',271 username: 'foo',272 password: 'bar',273 grant_type: 'password',274 scope: 'baz'275 },276 headers: { 'content-type': 'application/x-www-form-urlencoded', 'transfer-encoding': 'chunked' },277 method: 'POST',278 query: {}279 });280 var response = new Response({ body: {}, headers: {} });281 return handler.handle(request, response)282 .then(function(data) {283 model.request.should.equal(request);284 data.should.eql(token);285 })286 .catch(should.fail);287 });288 it('should not return custom attributes in a bearer token if the allowExtendedTokenAttributes is not set', function() {289 var token = { accessToken: 'foo', client: {}, refreshToken: 'bar', scope: 'foobar', user: {}, foo: 'bar' };290 var model = {291 getClient: function() { return { grants: ['password'] }; },292 getUser: function() { return {}; },293 saveToken: function() { return token; },294 validateScope: function() { return 'baz'; }295 };296 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });297 var request = new Request({298 body: {299 client_id: 12345,300 client_secret: 'secret',301 username: 'foo',302 password: 'bar',303 grant_type: 'password',304 scope: 'baz'305 },306 headers: { 'content-type': 'application/x-www-form-urlencoded', 'transfer-encoding': 'chunked' },307 method: 'POST',308 query: {}309 });310 var response = new Response({ body: {}, headers: {} });311 return handler.handle(request, response)312 .then(function() {313 should.exist(response.body.access_token);314 should.exist(response.body.refresh_token);315 should.exist(response.body.token_type);316 should.exist(response.body.scope);317 should.not.exist(response.body.foo);318 })319 .catch(should.fail);320 });321 it('should return custom attributes in a bearer token if the allowExtendedTokenAttributes is set', function() {322 var token = { accessToken: 'foo', client: {}, refreshToken: 'bar', scope: 'foobar', user: {}, foo: 'bar' };323 var model = {324 getClient: function() { return { grants: ['password'] }; },325 getUser: function() { return {}; },326 saveToken: function() { return token; },327 validateScope: function() { return 'baz'; }328 };329 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120, allowExtendedTokenAttributes: true });330 var request = new Request({331 body: {332 client_id: 12345,333 client_secret: 'secret',334 username: 'foo',335 password: 'bar',336 grant_type: 'password',337 scope: 'baz'338 },339 headers: { 'content-type': 'application/x-www-form-urlencoded', 'transfer-encoding': 'chunked' },340 method: 'POST',341 query: {}342 });343 var response = new Response({ body: {}, headers: {} });344 return handler.handle(request, response)345 .then(function() {346 should.exist(response.body.access_token);347 should.exist(response.body.refresh_token);348 should.exist(response.body.token_type);349 should.exist(response.body.scope);350 should.exist(response.body.foo);351 })352 .catch(should.fail);353 });354 });355 describe('getClient()', function() {356 it('should throw an error if `clientId` is invalid', function() {357 var model = {358 getClient: function() {},359 saveToken: function() {}360 };361 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });362 var request = new Request({ body: { client_id: 'øåâ¬Â£â°', client_secret: 'foo' }, headers: {}, method: {}, query: {} });363 try {364 handler.getClient(request);365 should.fail();366 } catch (e) {367 e.should.be.an.instanceOf(InvalidRequestError);368 e.message.should.equal('Invalid parameter: `client_id`');369 }370 });371 it('should throw an error if `clientSecret` is invalid', function() {372 var model = {373 getClient: function() {},374 saveToken: function() {}375 };376 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });377 var request = new Request({ body: { client_id: 'foo', client_secret: 'øåâ¬Â£â°' }, headers: {}, method: {}, query: {} });378 try {379 handler.getClient(request);380 should.fail();381 } catch (e) {382 e.should.be.an.instanceOf(InvalidRequestError);383 e.message.should.equal('Invalid parameter: `client_secret`');384 }385 });386 it('should throw an error if `client` is missing', function() {387 var model = {388 getClient: function() {},389 saveToken: function() {}390 };391 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });392 var request = new Request({ body: { client_id: 12345, client_secret: 'secret' }, headers: {}, method: {}, query: {} });393 return handler.getClient(request)394 .then(should.fail)395 .catch(function(e) {396 e.should.be.an.instanceOf(InvalidClientError);397 e.message.should.equal('Invalid client: client is invalid');398 });399 });400 it('should throw an error if `client.grants` is missing', function() {401 var model = {402 getClient: function() { return {}; },403 saveToken: function() {}404 };405 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });406 var request = new Request({ body: { client_id: 12345, client_secret: 'secret' }, headers: {}, method: {}, query: {} });407 return handler.getClient(request)408 .then(should.fail)409 .catch(function(e) {410 e.should.be.an.instanceOf(ServerError);411 e.message.should.equal('Server error: missing client `grants`');412 });413 });414 it('should throw an error if `client.grants` is invalid', function() {415 var model = {416 getClient: function() { return { grants: 'foobar' }; },417 saveToken: function() {}418 };419 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });420 var request = new Request({ body: { client_id: 12345, client_secret: 'secret' }, headers: {}, method: {}, query: {} });421 return handler.getClient(request)422 .then(should.fail)423 .catch(function(e) {424 e.should.be.an.instanceOf(ServerError);425 e.message.should.equal('Server error: `grants` must be an array');426 });427 });428 it('should throw a 401 error if the client is invalid and the request contains an authorization header', function() {429 var model = {430 getClient: function() {},431 saveToken: function() {}432 };433 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });434 var request = new Request({435 body: {},436 headers: { 'authorization': util.format('Basic %s', new Buffer('foo:bar').toString('base64')) },437 method: {},438 query: {}439 });440 var response = new Response({ body: {}, headers: {} });441 return handler.getClient(request, response)442 .then(should.fail)443 .catch(function(e) {444 e.should.be.an.instanceOf(InvalidClientError);445 e.code.should.equal(401);446 e.message.should.equal('Invalid client: client is invalid');447 response.get('WWW-Authenticate').should.equal('Basic realm="Service"');448 });449 });450 it('should return a client', function() {451 var client = { id: 12345, grants: [] };452 var model = {453 getClient: function() { return client; },454 saveToken: function() {}455 };456 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });457 var request = new Request({ body: { client_id: 12345, client_secret: 'secret' }, headers: {}, method: {}, query: {} });458 return handler.getClient(request)459 .then(function(data) {460 data.should.equal(client);461 })462 .catch(should.fail);463 });464 describe('with `password` grant type and `requireClientAuthentication` is false', function() {465 it('should return a client ', function() {466 var client = { id: 12345, grants: [] };467 var model = {468 getClient: function() { return client; },469 saveToken: function() {}470 };471 var handler = new TokenHandler({472 accessTokenLifetime: 120,473 model: model,474 refreshTokenLifetime: 120,475 requireClientAuthentication: {476 password: false477 }478 });479 var request = new Request({ body: { client_id: 'blah', grant_type: 'password'}, headers: {}, method: {}, query: {} });480 return handler.getClient(request)481 .then(function(data) {482 data.should.equal(client);483 })484 .catch(should.fail);485 });486 });487 describe('with `password` grant type and `requireClientAuthentication` is false and Authorization header', function() {488 it('should return a client ', function() {489 var client = { id: 12345, grants: [] };490 var model = {491 getClient: function() { return client; },492 saveToken: function() {}493 };494 var handler = new TokenHandler({495 accessTokenLifetime: 120,496 model: model,497 refreshTokenLifetime: 120,498 requireClientAuthentication: {499 password: false500 }501 });502 var request = new Request({503 body: { grant_type: 'password' },504 headers: { 'authorization': util.format('Basic %s', new Buffer('blah:').toString('base64')) },505 method: {},506 query: {}507 });508 return handler.getClient(request)509 .then(function(data) {510 data.should.equal(client);511 })512 .catch(should.fail);513 });514 });515 it('should support promises', function() {516 var model = {517 getClient: function() { return Promise.resolve({ grants: [] }); },518 saveToken: function() {}519 };520 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });521 var request = new Request({ body: { client_id: 12345, client_secret: 'secret' }, headers: {}, method: {}, query: {} });522 handler.getClient(request).should.be.an.instanceOf(Promise);523 });524 it('should support non-promises', function() {525 var model = {526 getClient: function() { return { grants: [] }; },527 saveToken: function() {}528 };529 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });530 var request = new Request({ body: { client_id: 12345, client_secret: 'secret' }, headers: {}, method: {}, query: {} });531 handler.getClient(request).should.be.an.instanceOf(Promise);532 });533 it('should support callbacks', function() {534 var model = {535 getClient: function(clientId, clientSecret, callback) { callback(null, { grants: [] }); },536 saveToken: function() {}537 };538 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });539 var request = new Request({ body: { client_id: 12345, client_secret: 'secret' }, headers: {}, method: {}, query: {} });540 handler.getClient(request).should.be.an.instanceOf(Promise);541 });542 });543 describe('getClientCredentials()', function() {544 it('should throw an error if `client_id` is missing', function() {545 var model = {546 getClient: function() {},547 saveToken: function() {}548 };549 var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });550 var request = new Request({ body: { client_secret: 'foo' }, headers: {}, method: {}, query: {} });551 try {552 handler.getClientCredentials(request);553 should.fail();554 } catch (e) {...
platformer_trap.js
Source:platformer_trap.js
1function enter(pi) {2 pi.getPlayer().getStat().heal(pi.getPlayer())3 switch (pi.getPlayer().getMapId()) {4 case 993001040:5 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4091, -2068));6 break;7 case 993001060:8 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4111, -3388));9 break;10 case 993001070:11 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-754, 92));12 break;13 case 993001080:14 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4129, -268));15 break;16 case 993001090:17 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4175, -688));18 break;19 case 993001100:20 pi.warp(pi.getPlayer().getMapId());21 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-3103, -208));22 break;23 case 993001110:24 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-300, 92));25 break;26 case 993001120:27 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4129, -88));28 break;29 case 993001130:30 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-754, 92));31 break;32 case 993001140:33 pi.warp(pi.getPlayer().getMapId());34 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-3104, -2128));35 break;36 case 993001150:37 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4129, -88));38 break;39 case 993001160:40 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4111, -3388));41 break;42 case 993001170:43 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4129, -268));44 break;45 case 993001180:46 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-510, 92));47 break;48 case 993001190:49 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-754, 92));50 break;51 case 993001200:52 pi.warp(pi.getPlayer().getMapId());53 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-2885, -148));54 break;55 case 993001210:56 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4148, 92));57 break;58 case 993001220:59 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-676, -268));60 break;61 case 993001230:62 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4129, -88));63 break;64 case 993001240:65 pi.warp(pi.getPlayer().getMapId());66 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CameraCtrl(0x0F, 1000, 600));67 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CameraCtrl(0x0D, 0, 1000, 300, 0));68 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CameraCtrl(0x0B, 5));69 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4129, -88));70 break;71 case 993001250:72 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4129, -88));73 break;74 case 993001260:75 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-754, 92));76 break;77 case 993001270:78 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4111, -3388));79 break;80 case 993001280:81 pi.warp(pi.getPlayer().getMapId());82 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-676, -273));83 break;84 case 993001290:85 pi.warp(pi.getPlayer().getMapId());86 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-3096, -208));87 break;88 case 993001300:89 pi.warp(pi.getPlayer().getMapId());90 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CameraCtrl(0x0F, 1000, 600));91 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CameraCtrl(0x0D, 0, 0, 0, 200));92 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-5218, 92));93 break;94 case 993001310:95 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-2964, 2132));96 break;97 case 993001320:98 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4129, -88));99 break;100 case 993001330:101 pi.warp(993001330);102 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-3464, -28));103 break;104 case 993001340:105 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-3514, -3748));106 break;107 case 993001350:108 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-3830, -3780));109 break;110 case 993001360:111 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4129, -88));112 break;113 case 993001370:114 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4129, -88));115 break;116 case 993001380:117 pi.warp(pi.getPlayer().getMapId());118 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CameraCtrl(0x0F, 1000, 600));119 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CameraCtrl(0x0D, 0, 1000, 300, 0));120 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CameraCtrl(0x0B, 5));121 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-4128, -88));122 break;123 case 993001390:124 pi.warp(pi.getPlayer().getMapId());125 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-3072, -88));126 break;127 case 993001400:128 pi.warp(pi.getPlayer().getMapId());129 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.CharReLocationPacket(-5226, -128));130 break;131 }132 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.SendPacket(694, "05 00 00 00 D0 07 00 00 00"));133 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.playSE("Sound/Ambience.img/warning"));134 var rand = Packages.server.Randomizer.nextInt(11);135 switch (pi.getPlayer().getMapId()) {136 case 993001180:137 break;138 default:139 switch (rand) {140 case 0:141 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070200, 500, "ÂêÂê... Á¶½ÉÇß¾î¾ßÁö.", ""));142 break;143 case 1:144 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070200, 500, "ÀÌ·± ÀÏ·Î Æ÷±âÇÏÁö ¸¶¶ó.", ""));145 break;146 case 2:147 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070200, 500, "¾Ñ! Èþ! ¿§! ÈÅ! µ¹ÆÄÇϴµ¥ ½ÇÆÐÇß¾î!", ""));148 break;149 case 3:150 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070200, 500, "¾Æ¹«¸® ºÁµµ ³Ê ½ºÄõÆ® 200°³¾¿ Çؾ߰ڴÙ.", ""));151 break;152 case 4:153 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070201, 500, "³ë-·ÂÀÌ ºÎÁ·ÇÑ °Í ¾Æ´Ñ°¡¿ä?", ""));154 break;155 case 5:156 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070201, 500, "À¸¾Ñ...Èû³»¿ä.", ""));157 break;158 case 6:159 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070202, 500, "¾ÆÇÁ´Ï±î ûÃáÀÌ´Ù.", ""));160 break;161 case 7:162 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070202, 500, "½´Æ® ºô·ÁÁÙ±î? È÷Èý.", ""));163 break;164 case 8:165 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070202, 500, "¿ôÀ¸¸é ¾ÈµÇÁö¸¸...È÷È÷Èý.", ""));166 break;167 case 9:168 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070203, 500, "³Í ÇÒ ¼ö ÀÖ´Ù°í »ý°¢ÇÑ´Ù. ¾Æ¸¶...", ""));169 break;170 case 10:171 pi.getClient().getSession().writeAndFlush(Packages.tools.packet.MaplePacket.OnYellowDlg(9070203, 500, "³ª¹«´Ãº¸°°ÀÌ ±À¶á ¿òÁ÷ÀÓÀ̱º.", ""));172 break;173 }174 break;175 }...
p2_api.test.js
Source:p2_api.test.js
...47 state: 'state',48 scope: 'custom_scope'49 }50 };51 const client = getClient(options);52 const mock = getAuth0ClientMock();53 expect(mock.WebAuth.mock.calls[0][0]).toMatchSnapshot();54 });55 });56 describe('should set authOpt according options', () => {57 it('should set sso:true when inside the universal login page', () => {58 setURL('https://me.auth0.com/');59 const options = {60 sso: true61 };62 const client = getClient(options);63 expect(client.authOpt.sso).toBe(true);64 });65 it('should set sso:false when inside the universal login page', () => {66 setURL('https://me.auth0.com/');67 const options = {68 sso: false69 };70 const client = getClient(options);71 expect(client.authOpt.sso).toBe(false);72 });73 it('should set sso:undefined when outside the universal login page', () => {74 setURL('https://other-url.auth0.com/');75 const options = {};76 const client = getClient(options);77 expect(client.authOpt.sso).toBe(undefined);78 });79 it('should set state from options.state', () => {80 const client = getClient({81 state: 'foo'82 });83 expect(client.authOpt.state).toBe('foo');84 });85 it('should set state from options.params.state', () => {86 const client = getClient({87 params: {88 state: 'foo'89 }90 });91 expect(client.authOpt.state).toBe('foo');92 });93 it('options.params.state should prevail over options.state', () => {94 const client = getClient({95 state: 'bar',96 params: {97 state: 'foo'98 }99 });100 expect(client.authOpt.state).toBe('foo');101 });102 it('should set nonce from options.nonce', () => {103 const client = getClient({104 nonce: 'foo'105 });106 expect(client.authOpt.nonce).toBe('foo');107 });108 it('should set nonce from options.params.nonce', () => {109 const client = getClient({110 params: {111 nonce: 'foo'112 }113 });114 expect(client.authOpt.nonce).toBe('foo');115 });116 it('options.params.nonce should prevail over options.nonce', () => {117 const client = getClient({118 nonce: 'bar',119 params: {120 nonce: 'foo'121 }122 });123 expect(client.authOpt.nonce).toBe('foo');124 });125 it('should set scope from options.params.scope', () => {126 const client = getClient({127 params: {128 scope: 'foo'129 }130 });131 expect(client.authOpt.scope).toBe('foo');132 });133 });134 });135 describe('logIn', () => {136 const assertCallWithCallback = (mock, callbackFunction) => {137 expect(mock.calls.length).toBe(1);138 expect(mock.calls[0][0]).toMatchSnapshot();139 mock.calls[0][1]();140 expect(callbackFunction.mock.calls.length).toBe(1);141 };142 describe('with social/enterprise (without username and email)', () => {143 it('should call authorize when redirect===true', () => {144 const client = getClient({145 redirect: true146 });147 const callback = jest.fn();148 client.logIn({}, {}, callback);149 const mock = getAuth0ClientMock();150 const authorizeMock = mock.WebAuth.mock.instances[0].authorize.mock;151 assertCallWithCallback(authorizeMock, callback);152 });153 it('should call popup.authorize when redirect===false', () => {154 const client = getClient({155 redirect: false156 });157 const callback = jest.fn();158 client.logIn({}, {}, callback);159 const mock = getAuth0ClientMock();160 const authorizeMock = mock.WebAuth.mock.instances[0].popup.authorize.mock;161 assertCallWithCallback(authorizeMock, callback);162 });163 });164 describe('with credentials', () => {165 it('should call client.login', () => {166 const client = getClient({167 redirect: true168 });169 const callback = jest.fn();170 client.logIn(171 {172 username: 'foo'173 },174 {},175 callback176 );177 const mock = getAuth0ClientMock();178 const loginMock = mock.WebAuth.mock.instances[0].login.mock;179 assertCallWithCallback(loginMock, callback);180 });181 it('should use the provided login_hint', () => {182 const client = getClient({183 redirect: true184 });185 const callback = jest.fn();186 client.logIn(187 {188 email: 'foo',189 login_hint: 'valid_hint@test.com'190 },191 {192 login_hint: 'invalid_hint@test.com'193 },194 callback195 );196 const mock = getAuth0ClientMock();197 const loginMock = mock.WebAuth.mock.instances[0].login.mock;198 expect(loginMock.calls[0][0].login_hint).toBe('valid_hint@test.com');199 });200 it('should call popup.loginWithCredentials when redirect is false and sso is false', () => {201 const client = getClient({202 redirect: false,203 sso: false204 });205 const callback = jest.fn();206 client.logIn(207 {208 username: 'foo'209 },210 {},211 callback212 );213 const mock = getAuth0ClientMock();214 const loginWithCredentialsMock =215 mock.WebAuth.mock.instances[0].popup.loginWithCredentials.mock;216 assertCallWithCallback(loginWithCredentialsMock, callback);217 });218 it('should call popup.loginWithCredentials when redirect is false and sso is true', () => {219 const client = getClient({220 redirect: false,221 sso: true222 });223 const callback = jest.fn();224 client.logIn(225 {226 username: 'foo'227 },228 {},229 callback230 );231 const mock = getAuth0ClientMock();232 const loginWithCredentialsMock =233 mock.WebAuth.mock.instances[0].popup.loginWithCredentials.mock;234 assertCallWithCallback(loginWithCredentialsMock, callback);235 });236 });237 });238 it('passwordlessStart should call client.passwordlessStart', () => {239 const client = getClient({});240 client.passwordlessStart(241 {242 foo: 'bar'243 },244 () => {}245 );246 const { mock } = client.client.passwordlessStart;247 expect(mock.calls.length).toBe(1);248 expect(mock.calls[0]).toMatchSnapshot();249 });250 it('passwordlessVerify should call client.passwordlessLogin', () => {251 const client = getClient({});252 client.passwordlessVerify(253 {254 foo: 'bar'255 },256 () => {}257 );258 const { mock } = client.client.passwordlessLogin;259 expect(mock.calls.length).toBe(1);260 expect(mock.calls[0]).toMatchSnapshot();261 });262 it('getUserCountry should call getUserCountry', () => {263 const client = getClient({});264 client.getUserCountry('cb');265 const { mock } = client.client.client.getUserCountry;266 expect(mock.calls.length).toBe(1);267 expect(mock.calls[0]).toMatchSnapshot();268 });269 it('getSSOData should call client.client.getSSOData', () => {270 const client = getClient({});271 client.getSSOData(true, () => {});272 const { mock } = client.client.client.getSSOData;273 expect(mock.calls.length).toBe(1);274 expect(mock.calls[0]).toMatchSnapshot();275 });276 describe('parseHash', () => {277 it('should pass __enableIdPInitiatedLogin:false when options._enableImpersonation and options._enableIdPInitiatedLogin are not present', () => {278 const client = getClient({});279 client.parseHash('hash', 'cb');280 const mock = getAuth0ClientMock();281 const parseHashMock = mock.WebAuth.mock.instances[0].parseHash.mock;282 expect(parseHashMock.calls.length).toBe(1);283 expect(parseHashMock.calls[0]).toMatchSnapshot();284 });285 it('should pass __enableIdPInitiatedLogin when options._enableImpersonation===true', () => {286 const client = getClient({287 _enableImpersonation: true288 });289 client.parseHash('hash', 'cb');290 const mock = getAuth0ClientMock();291 const parseHashMock = mock.WebAuth.mock.instances[0].parseHash.mock;292 expect(parseHashMock.calls.length).toBe(1);293 expect(parseHashMock.calls[0]).toMatchSnapshot();294 });295 it('should pass __enableIdPInitiatedLogin when options._enableIdPInitiatedLogin===true', () => {296 const client = getClient({297 _enableIdPInitiatedLogin: true298 });299 client.parseHash('hash', 'cb');300 const mock = getAuth0ClientMock();301 const parseHashMock = mock.WebAuth.mock.instances[0].parseHash.mock;302 expect(parseHashMock.calls.length).toBe(1);303 expect(parseHashMock.calls[0]).toMatchSnapshot();304 });305 });...
test_runner.js
Source:test_runner.js
...58 let client;59 beforeEach(() => {60 client = new this.ClientKlass({token:token});61 });62 function getClient(){63 return client;64 }65 describe('#agent', () => {66 let adapterPath = 'agents';67 showTests.call(this, getClient, adapterPath);68 indexTests.call(this, getClient, adapterPath);69 });70 describe('#agent_profile', () => {71 let adapterPath = 'agentProfiles';72 complexShowTests.call(this, getClient, adapterPath);73 indexTests.call(this, getClient, adapterPath);74 });75 describe('#broker_office', () => {76 let adapterPath = 'brokerOffices';77 complexShowTests.call(this, getClient, adapterPath);78 indexTests.call(this, getClient, adapterPath);79 });80 describe('#collection', () => {81 let adapterPath = 'collections';82 let attributes = {name: 'My Collection'};83 createTests.call(this, getClient, adapterPath, attributes);84 showTests.call(this, getClient, adapterPath);85 indexTests.call(this, getClient, adapterPath);86 updateTests.call(this, getClient, adapterPath, attributes);87 destroyTests.call(this, getClient, adapterPath);88 inviteTests.call(this, getClient, adapterPath);89 acceptInviteTests.call(this, getClient, adapterPath);90 uninviteTests.call(this, getClient, adapterPath);91 it('#add', (done) => {92 getClient()[adapterPath].add({id: 5, property_ids: [sampleComplexId]}).then(res => {93 assert.exists(res.body)94 done();95 });96 });97 it('#remove', (done) => {98 getClient()[adapterPath].remove({id: 5, property_ids: [sampleComplexId]}).then(res => {99 assert.exists(res.body)100 done();101 });102 });103 it('#search', (done) => {104 getClient()[adapterPath].search({id: 5, filter: filter, market_id: market_id, page: page}).then(res => {105 assert.exists(res.body)106 done();107 });108 });109 it('#cluster', (done) => {110 getClient()[adapterPath].cluster({id: 5, filter: filter, market_id: market_id, page: page}).then(res => {111 assert.exists(res.body)112 done();113 });114 });115 });116 describe('#market', () => {117 let adapterPath = 'markets';118 let attributes = {name: 'Greater Austin TX'};119 createTests.call(this, getClient, adapterPath, attributes);120 showTests.call(this, getClient, adapterPath);121 indexTests.call(this, getClient, adapterPath);122 updateTests.call(this, getClient, adapterPath, attributes);123 destroyTests.call(this, getClient, adapterPath);124 });125 describe('#open_house', () => {126 let adapterPath = 'openHouses';127 complexShowTests.call(this, getClient, adapterPath);128 indexTests.call(this, getClient, adapterPath);129 });130 describe('#listing', () => {131 let adapterPath = 'listings';132 complexShowTests.call(this, getClient, adapterPath);133 it('#search', (done) => {134 getClient()[adapterPath].search({filter: filter, market_id: market_id, page: page}).then(res => {135 assert.exists(res.body)136 done();137 });138 });139 it('#cluster', (done) => {140 getClient()[adapterPath].cluster({filter: filter, market_id: market_id, page: page}).then(res => {141 assert.exists(res.body)142 done();143 });144 });145 });146 describe('#property', () => {147 let adapterPath = 'properties';148 complexShowTests.call(this, getClient, adapterPath);149 it('#search', (done) => {150 getClient()[adapterPath].search({filter: filter, market_id: market_id, page: page}).then(res => {151 assert.exists(res.body)152 done();153 });154 });155 it('#cluster', (done) => {156 getClient()[adapterPath].cluster({filter: filter, market_id: market_id, page: page}).then(res => {157 assert.exists(res.body)158 done();159 });160 });161 });162 describe('#saved_search', () => {163 let adapterPath = 'savedSearches';164 let attributes = {name: 'My Saved Search'};165 createTests.call(this, getClient, adapterPath, attributes);166 showTests.call(this, getClient, adapterPath);167 indexTests.call(this, getClient, adapterPath);168 updateTests.call(this, getClient, adapterPath, attributes);169 destroyTests.call(this, getClient, adapterPath);170 inviteTests.call(this, getClient, adapterPath);171 acceptInviteTests.call(this, getClient, adapterPath);172 uninviteTests.call(this, getClient, adapterPath);173 it('#search', (done) => {174 getClient()[adapterPath].search({id: 5, filter: filter, market_id: market_id, page: page}).then(res => {175 assert.exists(res.body)176 done();177 });178 });179 it('#cluster', (done) => {180 getClient()[adapterPath].cluster({id: 5, filter: filter, market_id: market_id, page: page}).then(res => {181 assert.exists(res.body)182 done();183 });184 });185 });186 describe('#site', () => {187 let adapterPath = 'sites';188 meTests.call(this, getClient, adapterPath);189 });190 describe('#suggestion', () => {191 let adapterPath = 'suggestions';192 indexTests.call(this, getClient, adapterPath);193 it('#search', (done) => {194 getClient()[adapterPath].search({filter: filter, market_id: market_id, page: page, query: 'Buda'}).then(res => {195 assert.exists(res.body)196 done();197 });198 });199 });200 describe('#user', () => {201 let adapterPath = 'users';202 let attributes = {email: 'foo@realsavvy.com'};203 createTests.call(this, getClient, adapterPath, attributes);204 showTests.call(this, getClient, adapterPath);205 indexTests.call(this, getClient, adapterPath);206 updateTests.call(this, getClient, adapterPath, attributes);207 destroyTests.call(this, getClient, adapterPath);208 meTests.call(this, getClient, adapterPath);...
ipc.js
Source:ipc.js
...26const options = {27 "grpc.max_receive_message_length": 1024 * 1024 * 1000,28 "grpc.max_send_message_length": 1024 * 1024 * 100029}30function getClient() {31 if (_client) {32 return _client33 }34 const md = new grpc.Metadata();35 md.set("authorization", `bearer ${global.password}`)36 if (global.caPem !== "") {37 const creds = grpc.credentials.createFromMetadataGenerator((params, callback) => {38 return callback(null, md)39 });40 _client = new Yak(41 global.defaultYakGRPCAddr,42 // grpc.credentials.createInsecure(),43 grpc.credentials.combineChannelCredentials(grpc.credentials.createSsl(44 (Buffer.from(global.caPem, "latin1")), null, null, {45 checkServerIdentity: ((hostname, cert) => {46 return undefined47 }),48 }49 ), creds),50 options,51 )52 } else {53 _client = new Yak(54 global.defaultYakGRPCAddr,55 grpc.credentials.createInsecure(),56 options,57 )58 }59 return getClient()60}61module.exports = {62 clearing: () => {63 require("./handlers/yakLocal").clearing();64 },65 registerIPC: (win) => {66 ipcMain.handle("yakit-connect-status", () => {67 return {68 addr: global.defaultYakGRPCAddr,69 isTLS: !!global.caPem,70 }71 })72 ipcMain.handle("echo", async (e, text) => {73 getClient().Echo({74 text: text,75 }, (err, rsp) => {76 });77 return text78 })79 require("./handlers/execYak")(win, getClient);80 require("./handlers/listenPort")(win, getClient);81 require("./handlers/mitm")(win, getClient);82 require("./handlers/checkYakEnv")(win, (addr, password, caPem) => {83 // æ¸
空èæ°æ®84 if (_client) _client.close();85 _client = null;86 global.password = "";87 global.caPem = "";...
marriagequestion.js
Source:marriagequestion.js
...40 otherChar.dropMessage(1, "Your partner has accepted your request.");41 otherChar.setMarriageQuestLevel(50);42 cm.getPlayer().setMarriageQuestLevel(50);43 if (otherChar.getItemQuantity(2240000, false) > 0) {44 MapleInventoryManipulator.removeById(otherChar.getClient(), MapleInventoryType.USE, 2240000, 1, false, false);45 MapleInventoryManipulator.addById(otherChar.getClient(), 4031358, 1, "slut!");46 MapleInventoryManipulator.addById(otherChar.getClient(), 4031357, 1, "cunt!");47 cm.gainItem(4031358, 1);48 } else if (otherChar.getItemQuantity(2240001, false) > 0) {49 MapleInventoryManipulator.removeById(otherChar.getClient(), MapleInventoryType.USE, 2240001, 1, false, false);50 MapleInventoryManipulator.addById(otherChar.getClient(), 4031360, 1, "shit!");51 MapleInventoryManipulator.addById(otherChar.getClient(), 4031359, 1, "shit!");52 cm.gainItem(4031360, 1);53 } else if (otherChar.getItemQuantity(2240002, false) > 0) {54 MapleInventoryManipulator.removeById(otherChar.getClient(), MapleInventoryType.USE, 2240002, 1, false, false);55 MapleInventoryManipulator.addById(otherChar.getClient(), 4031362, 1, "shit!");56 MapleInventoryManipulator.addById(otherChar.getClient(), 4031361, 1, "shit!");57 cm.gainItem(4031362, 1);58 } else if (otherChar.getItemQuantity(2240003, false) > 0) {59 MapleInventoryManipulator.removeById(otherChar.getClient(), MapleInventoryType.USE, 2240003, 1, false, false);60 MapleInventoryManipulator.addById(otherChar.getClient(), 4031364, 1, "shit!");61 MapleInventoryManipulator.addById(otherChar.getClient(), 4031363, 1, "shit!");62 cm.gainItem(4031364, 1);63 }64 } else {65 cm.sendOk("There seems to be an error with the system. Try again ?");66 otherChar.dropMessage(1, "There seems to be an error with the system. Try again ?.");67 }68 cm.dispose();69 }...
index.js
Source:index.js
...6 * @FilePath: \WEB-OSS-Browser\src\api\index.js7 * @åè½æè¿°8 */9import OSS from "ali-oss";10export function getClient() {11 return new OSS(JSON.parse(window.localStorage.getItem('client')) || {});12}13// è·åãæ件/ç®å½ãå表14export const fileList = (prefix, marker) => getClient().list({ prefix, delimiter: '/', 'max-keys': 1000, marker })15// è·åãæ件/ç®å½ãå表ï¼å
¨é¨ï¼ 16export const allList = (prefix) => getClient().list({ prefix, 'max-keys': 1000 })17// 继ç»ååºæ件ï¼ä¸»è¦ç¨äºéå½åç®å½ï¼18export const maxList = (marker) => getClient().list({ marker, 'max-keys': 1000 })19export const copy = (key, file) => getClient().copy(key, file)20// è·åä¸è½½å°å21export const signatureUrl = (key, response) => getClient().signatureUrl(key, { response })22// åçä¸ä¼ ï¼æç¹ç»ä¼ ï¼23export const multipartUpload = async (key, file, options = {}, client) => {24 return client.multipartUpload(key, file, options)25}26// åçä¸ä¼ ï¼ç¼è¾å¨ï¼27export const editorMultipartUpload = (key, file, options = {}) => getClient().multipartUpload(key, file, options)28// åçä¸ä¼ ï¼æ®éå¤ç¨ï¼29export const clipMultipartUpload = (key, file, options = {}) => getClient().multipartUpload(key, file, options)30// ç®åä¸ä¼ 31export const simplePut = (key, file) => getClient().put(key, file)32// æ¹éå é¤33export const deleteMulti = (keys) => getClient().deleteMulti(keys, {34 quiet: true35})36// æ¹éå é¤37export const deleteKey = (key) => getClient().delete(key, {38 quiet: true...
Using AI Code Generation
1describe('Cypress', () => {2 it('is working', () => {3 expect(true).to.equal(true)4 })5 it('can request', () => {6 })7})8describe('Cypress', () => {9 it('is working', () => {10 expect(true).to.equal(true)11 })12 it('can request', () => {13 })14})15describe('Cypress', () => {16 it('is working', () => {17 expect(true).to.equal(true)18 })19 it('can request', () => {20 })21})22describe('Cypress', () => {23 it('is working', () => {24 expect(true).to.equal(true)25 })26 it('can request', () => {27 })28})29describe('Cypress', () => {30 it('is working', () => {31 expect(true).to.equal(true)32 })33 it('can request', () => {34 })35})36describe('Cypress', () => {37 it('is working', () => {38 expect(true).to.equal(true)39 })40 it('can request', () => {41 })42})43describe('Cypress', () => {44 it('is working', () => {45 expect(true).to.equal(true)46 })47 it('can request', () => {48 })49})50describe('Cypress', () => {51 it('is working', () => {52 expect(true).to.equal(true)53 })54 it('can request', () => {
Using AI Code Generation
1Cypress.on('window:before:load', (win) => {2 win.getClient = () => {3 }4})5Cypress.on('window:before:load', (win) => {6 win.getClient = () => {7 }8})9Cypress.Commands.add('getClient', () => {10 cy.window().then((win) => {11 return win.getClient()12 })13})14it('can use a custom command to get client', () => {15 cy.getClient().then((client) => {16 expect(client).to.be.ok17 })18})19it('can use a custom command to get client', () => {20 cy.getClient().then((client) => {21 expect(client).to.be.ok22 })23})24it('can use a custom command to get client', () => {25 cy.getClient().then((client) => {26 expect(client).to.be.ok27 })28})29it('can use a custom command to get client', () => {30 cy.getClient().then((client) => {31 expect(client).to.be.ok32 })33})34it('can use a custom command to get client', () => {35 cy.getClient().then((client) => {36 expect(client).to.be.ok37 })38})39it('can use a custom command to get client', () => {40 cy.getClient().then((client) => {41 expect(client).to.be.ok42 })43})44it('can use a custom command to get client', () => {
Using AI Code Generation
1Cypress.on('window:before:load', (win) => {2 win.getClient = () => {3 }4})5describe('test', () => {6 it('test', () => {7 cy.server()8 cy.route('POST', '**/users').as('postUser')9 cy.get('.network-post').click()10 cy.wait('@postUser').then((xhr) => {11 const client = getClient()12 console.log(client)13 })14 })15})16cy.wait('@postUser').then((xhr) => {17 const client = getClient()18 const response = client.getResponse(xhr)19 expect(response.body).to.include('Your form has been submitted!')20})21cy.wait('@postUser').then((xhr) => {22 const client = getClient()23 const request = client.getRequest(xhr)24 expect(request.body).to.include('
Using AI Code Generation
1describe('Cypress Demo', function() {2 it('Cypress Demo', function() {3 cy.get('[name="q"]').type('Cypress')4 cy.get('.FPdoLc > center > .gNO89b').click()5 cy.get('.LC20lb').click()6 cy.get('.h1').should('contain', 'Cypress.io')7 cy.get('.navbar-brand').should('contain', 'Cypress.io')8 cy.get('.navbar-brand').should('have.attr', 'href').and('include', 'cypress.io')9 })10})11describe('Cypress Demo', function() {12 it('Cypress Demo', function() {13 cy.get('[name="q"]').type('Cypress')14 cy.get('.FPdoLc > center > .gNO89b').click()15 cy.get('.LC20lb').click()16 cy.get('.h1').should('contain', 'Cypress.io')17 cy.get('.navbar-brand').should('contain', 'Cypress.io')18 cy.get('.navbar-brand').should('have.attr', 'href').and('include', 'cypress.io')19 cy.getBrowser().should('be', 'chrome')20 })21})22describe('Cypress Demo', function() {23 it('Cypress Demo', function() {24 cy.get('[name="q"]').type('Cypress')25 cy.get('.FPdoLc > center > .gNO89b').click()26 cy.get('.LC20lb').click()27 cy.get('.h1').should('contain', 'Cypress.io')28 cy.get('.navbar-brand').should('contain', 'Cypress.io')29 cy.get('.navbar-brand').should('have.attr', 'href').and('include', 'cypress.io')30 cy.getBrowser().should('be', 'chrome')31 cy.getBrowserVersion().should('be', '92.0.4515.159')32 })33})34describe('Cypress Demo', function() {35 it('Cypress Demo', function() {36 cy.get('[name
Using AI Code Generation
1Cypress.Commands.add("getClient", () => {2 return cy.window().its("app.$store.state.client");3});4describe("Test", () => {5 it("test", () => {6 cy.getClient().then((client) => {7 });8 });9});
Using AI Code Generation
1Cypress.Commands.add("getClient", () => {2 return cy.window().then((win) => {3 return win.client;4 });5});6Cypress.Commands.add("getClient", () => {7 return cy.window().then((win) => {8 return win.client;9 });10});11Cypress.Commands.add("getClient", () => {12 return cy.window().then((win) => {13 return win.client;14 });15});16Cypress.Commands.add("getClient", () => {17 return cy.window().then((win) => {18 return win.client;19 });20});21Cypress.Commands.add("getClient", () => {22 return cy.window().then((win) => {23 return win.client;24 });25});26Cypress.Commands.add("getClient", () => {27 return cy.window().then((win) => {28 return win.client;29 });30});31Cypress.Commands.add("getClient", () => {32 return cy.window().then((win) => {33 return win.client;34 });35});
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!