|
1 | 1 | /* eslint-disable no-process-env */ |
2 | 2 | import { createHash } from 'node:crypto'; |
3 | 3 | import { ProjectType } from 'testkit/gql/graphql'; |
| 4 | +import * as GraphQLSchema from 'testkit/gql/graphql'; |
4 | 5 | import { createCLI, schemaCheck, schemaPublish } from '../../testkit/cli'; |
5 | 6 | import { cliOutputSnapshotSerializer } from '../../testkit/cli-snapshot-serializer'; |
6 | 7 | import { initSeed } from '../../testkit/seed'; |
@@ -497,3 +498,145 @@ test('schema:check gives correct error message for missing `--service` name flag |
497 | 498 | - Missing service name |
498 | 499 | `); |
499 | 500 | }); |
| 501 | + |
| 502 | +test('schema:check without `--target` flag fails for organization access token', async ({ |
| 503 | + expect, |
| 504 | +}) => { |
| 505 | + const { createOrg } = await initSeed().createOwner(); |
| 506 | + const { createOrganizationAccessToken } = await createOrg(); |
| 507 | + const privateKey = await createOrganizationAccessToken({ |
| 508 | + permissions: ['schemaCheck:create', 'project:describe'], |
| 509 | + resources: { |
| 510 | + mode: GraphQLSchema.ResourceAssignmentMode.All, |
| 511 | + }, |
| 512 | + }); |
| 513 | + |
| 514 | + await expect( |
| 515 | + schemaCheck([ |
| 516 | + '--registry.accessToken', |
| 517 | + privateKey, |
| 518 | + '--author', |
| 519 | + 'Kamil', |
| 520 | + 'fixtures/init-schema.graphql', |
| 521 | + ]), |
| 522 | + ).rejects.toMatchInlineSnapshot(` |
| 523 | + :::::::::::::::: CLI FAILURE OUTPUT ::::::::::::::: |
| 524 | + exitCode------------------------------------------: |
| 525 | + 2 |
| 526 | + stderr--------------------------------------------: |
| 527 | + › Error: Missing 1 required argument: |
| 528 | + › TARGET The target on which the action is performed. This can either be a |
| 529 | + › slug following the format "$organizationSlug/$projectSlug/$targetSlug" |
| 530 | + › (e.g "the-guild/graphql-hive/staging") or an UUID (e.g. |
| 531 | + › "a0f4c605-6541-4350-8cfe-b31f21a4bf80"). [102] |
| 532 | + › > See https://__URL__ for |
| 533 | + › a complete list of error codes and recommended fixes. |
| 534 | + › To disable this message set HIVE_NO_ERROR_TIP=1 |
| 535 | + stdout--------------------------------------------: |
| 536 | + __NONE__ |
| 537 | + `); |
| 538 | +}); |
| 539 | + |
| 540 | +test('schema:check with `--target` flag succeeds for organization access token', async ({ |
| 541 | + expect, |
| 542 | +}) => { |
| 543 | + const { createOrg } = await initSeed().createOwner(); |
| 544 | + const { createOrganizationAccessToken, createProject, organization } = await createOrg(); |
| 545 | + const { project, target } = await createProject(); |
| 546 | + const privateKey = await createOrganizationAccessToken({ |
| 547 | + permissions: ['schemaCheck:create', 'project:describe'], |
| 548 | + resources: { |
| 549 | + mode: GraphQLSchema.ResourceAssignmentMode.All, |
| 550 | + }, |
| 551 | + }); |
| 552 | + |
| 553 | + await expect( |
| 554 | + schemaCheck([ |
| 555 | + '--registry.accessToken', |
| 556 | + privateKey, |
| 557 | + '--author', |
| 558 | + 'Kamil', |
| 559 | + '--target', |
| 560 | + `${organization.slug}/${project.slug}/${target.slug}`, |
| 561 | + 'fixtures/init-schema.graphql', |
| 562 | + ]), |
| 563 | + ).resolves.toMatchInlineSnapshot(` |
| 564 | + :::::::::::::::: CLI SUCCESS OUTPUT ::::::::::::::::: |
| 565 | +
|
| 566 | + stdout--------------------------------------------: |
| 567 | + ✔ Schema registry is empty, nothing to compare your schema with. |
| 568 | + View full report: |
| 569 | + http://__URL__ |
| 570 | + `); |
| 571 | +}); |
| 572 | + |
| 573 | +test('schema:publish without `--target` flag fails for organization access token', async ({ |
| 574 | + expect, |
| 575 | +}) => { |
| 576 | + const { createOrg } = await initSeed().createOwner(); |
| 577 | + const { createOrganizationAccessToken } = await createOrg(); |
| 578 | + const privateKey = await createOrganizationAccessToken({ |
| 579 | + permissions: ['project:describe', 'schemaVersion:publish'], |
| 580 | + resources: { |
| 581 | + mode: GraphQLSchema.ResourceAssignmentMode.All, |
| 582 | + }, |
| 583 | + }); |
| 584 | + |
| 585 | + await expect( |
| 586 | + schemaPublish([ |
| 587 | + '--registry.accessToken', |
| 588 | + privateKey, |
| 589 | + '--author', |
| 590 | + 'Kamil', |
| 591 | + |
| 592 | + 'fixtures/init-schema.graphql', |
| 593 | + ]), |
| 594 | + ).rejects.toMatchInlineSnapshot(` |
| 595 | + :::::::::::::::: CLI FAILURE OUTPUT ::::::::::::::: |
| 596 | + exitCode------------------------------------------: |
| 597 | + 2 |
| 598 | + stderr--------------------------------------------: |
| 599 | + › Error: Missing 1 required argument: |
| 600 | + › TARGET The target on which the action is performed. This can either be a |
| 601 | + › slug following the format "$organizationSlug/$projectSlug/$targetSlug" |
| 602 | + › (e.g "the-guild/graphql-hive/staging") or an UUID (e.g. |
| 603 | + › "a0f4c605-6541-4350-8cfe-b31f21a4bf80"). [102] |
| 604 | + › > See https://__URL__ for |
| 605 | + › a complete list of error codes and recommended fixes. |
| 606 | + › To disable this message set HIVE_NO_ERROR_TIP=1 |
| 607 | + stdout--------------------------------------------: |
| 608 | + __NONE__ |
| 609 | + `); |
| 610 | +}); |
| 611 | + |
| 612 | +test('schema:publish with `--target` flag succeeds for organization access token', async ({ |
| 613 | + expect, |
| 614 | +}) => { |
| 615 | + const { createOrg } = await initSeed().createOwner(); |
| 616 | + const { createOrganizationAccessToken, organization, createProject } = await createOrg(); |
| 617 | + const { project, target } = await createProject(); |
| 618 | + const privateKey = await createOrganizationAccessToken({ |
| 619 | + permissions: ['project:describe', 'schemaVersion:publish'], |
| 620 | + resources: { |
| 621 | + mode: GraphQLSchema.ResourceAssignmentMode.All, |
| 622 | + }, |
| 623 | + }); |
| 624 | + |
| 625 | + await expect( |
| 626 | + schemaPublish([ |
| 627 | + '--registry.accessToken', |
| 628 | + privateKey, |
| 629 | + '--author', |
| 630 | + 'Kamil', |
| 631 | + '--target', |
| 632 | + `${organization.slug}/${project.slug}/${target.slug}`, |
| 633 | + 'fixtures/init-schema.graphql', |
| 634 | + ]), |
| 635 | + ).resolves.toMatchInlineSnapshot(` |
| 636 | + :::::::::::::::: CLI SUCCESS OUTPUT ::::::::::::::::: |
| 637 | +
|
| 638 | + stdout--------------------------------------------: |
| 639 | + ✔ Published initial schema. |
| 640 | + ℹ Available at http://__URL__ |
| 641 | + `); |
| 642 | +}); |
0 commit comments