|
1 | 1 | import { expect } from 'chai';
|
2 | 2 | import path from 'path';
|
| 3 | +import fs from 'fs'; |
3 | 4 | import { getFiles, existsMustBeDir } from '../../src/utils';
|
| 5 | +import { load as yamlLoad } from 'js-yaml'; |
4 | 6 | import { setupRecording, testNameToWorkingDirectory } from './e2e-utils';
|
5 | 7 | import { dump, deploy } from '../../src';
|
6 | 8 |
|
@@ -58,6 +60,128 @@ describe('#end-to-end deploy', function () {
|
58 | 60 |
|
59 | 61 | recordingDone();
|
60 | 62 | });
|
| 63 | + |
| 64 | + it('should deploy without deleting resources if AUTH0_ALLOW_DELETE is false', async function () { |
| 65 | + const { recordingDone } = await setupRecording(this.test?.title); |
| 66 | + |
| 67 | + // Loading tenant with a good bit of config |
| 68 | + await deploy({ |
| 69 | + input_file: `${__dirname}/testdata/lots-of-configuration/tenant.yaml`, |
| 70 | + config: { |
| 71 | + AUTH0_DOMAIN, |
| 72 | + AUTH0_CLIENT_ID, |
| 73 | + AUTH0_CLIENT_SECRET, |
| 74 | + AUTH0_ACCESS_TOKEN, |
| 75 | + AUTH0_ALLOW_DELETE: false, |
| 76 | + }, |
| 77 | + }); |
| 78 | + |
| 79 | + // Applying configuration to clear tenant out |
| 80 | + await deploy({ |
| 81 | + input_file: `${__dirname}/testdata/empty-tenant/tenant.yaml`, |
| 82 | + config: { |
| 83 | + AUTH0_DOMAIN, |
| 84 | + AUTH0_CLIENT_ID, |
| 85 | + AUTH0_CLIENT_SECRET, |
| 86 | + AUTH0_ACCESS_TOKEN, |
| 87 | + AUTH0_ALLOW_DELETE: false, |
| 88 | + }, |
| 89 | + }); |
| 90 | + |
| 91 | + const workDirectory = testNameToWorkingDirectory(this.test?.title); |
| 92 | + |
| 93 | + // Perform a subsequent dump to know the new state of remote |
| 94 | + await dump({ |
| 95 | + output_folder: workDirectory, |
| 96 | + format: 'yaml', |
| 97 | + config: { |
| 98 | + AUTH0_DOMAIN, |
| 99 | + AUTH0_CLIENT_ID, |
| 100 | + AUTH0_CLIENT_SECRET, |
| 101 | + AUTH0_ACCESS_TOKEN, |
| 102 | + }, |
| 103 | + }); |
| 104 | + |
| 105 | + const files = getFiles(workDirectory, ['.yaml']); |
| 106 | + expect(files).to.have.length(1); |
| 107 | + expect(files[0]).to.equal(path.join(workDirectory, 'tenant.yaml')); |
| 108 | + |
| 109 | + const yaml = yamlLoad(fs.readFileSync(files[0])); |
| 110 | + |
| 111 | + expect(yaml.emailTemplates.length).to.be.above(0); |
| 112 | + expect(yaml.rules.length).to.be.above(0); |
| 113 | + expect(yaml.pages.length).to.be.above(0); |
| 114 | + expect(yaml.clients.length).to.be.above(0); |
| 115 | + expect(yaml.databases.length).to.be.above(0); |
| 116 | + expect(yaml.connections.length).to.be.above(0); |
| 117 | + expect(yaml.roles.length).to.be.above(0); |
| 118 | + expect(yaml.guardianFactorProviders.length).to.be.above(0); |
| 119 | + expect(yaml.guardianFactorTemplates.length).to.be.above(0); |
| 120 | + expect(yaml.actions.length).to.be.above(0); |
| 121 | + expect(yaml.organizations.length).to.be.above(0); |
| 122 | + expect(yaml.logStreams.length).to.be.above(0); |
| 123 | + |
| 124 | + recordingDone(); |
| 125 | + }); |
| 126 | + |
| 127 | + it('should deploy while deleting resources if AUTH0_ALLOW_DELETE is true', async function () { |
| 128 | + const { recordingDone } = await setupRecording(this.test?.title); |
| 129 | + |
| 130 | + // Loading tenant with a good bit of config |
| 131 | + await deploy({ |
| 132 | + input_file: `${__dirname}/testdata/lots-of-configuration/tenant.yaml`, |
| 133 | + config: { |
| 134 | + AUTH0_DOMAIN, |
| 135 | + AUTH0_CLIENT_ID, |
| 136 | + AUTH0_CLIENT_SECRET, |
| 137 | + AUTH0_ACCESS_TOKEN, |
| 138 | + AUTH0_ALLOW_DELETE: true, |
| 139 | + }, |
| 140 | + }); |
| 141 | + |
| 142 | + // Applying configuration to clear tenant out |
| 143 | + await deploy({ |
| 144 | + input_file: `${__dirname}/testdata/empty-tenant/tenant.yaml`, |
| 145 | + config: { |
| 146 | + AUTH0_DOMAIN, |
| 147 | + AUTH0_CLIENT_ID, |
| 148 | + AUTH0_CLIENT_SECRET, |
| 149 | + AUTH0_ACCESS_TOKEN, |
| 150 | + AUTH0_ALLOW_DELETE: true, |
| 151 | + }, |
| 152 | + }); |
| 153 | + |
| 154 | + const workDirectory = testNameToWorkingDirectory(this.test?.title); |
| 155 | + |
| 156 | + // Perform a subsequent dump to know the new state of remote |
| 157 | + await dump({ |
| 158 | + output_folder: workDirectory, |
| 159 | + format: 'yaml', |
| 160 | + config: { |
| 161 | + AUTH0_DOMAIN, |
| 162 | + AUTH0_CLIENT_ID, |
| 163 | + AUTH0_CLIENT_SECRET, |
| 164 | + AUTH0_ACCESS_TOKEN, |
| 165 | + }, |
| 166 | + }); |
| 167 | + |
| 168 | + const files = getFiles(workDirectory, ['.yaml']); |
| 169 | + expect(files).to.have.length(1); |
| 170 | + expect(files[0]).to.equal(path.join(workDirectory, 'tenant.yaml')); |
| 171 | + |
| 172 | + const yaml = yamlLoad(fs.readFileSync(files[0])); |
| 173 | + |
| 174 | + expect(yaml.rules).to.have.length(0); |
| 175 | + expect(yaml.clients).to.have.length(2); //Accounting for Deploy CLI and Default App client |
| 176 | + expect(yaml.databases).to.have.length(1); // Default user database |
| 177 | + expect(yaml.connections).to.have.length(0); |
| 178 | + expect(yaml.roles).to.have.length(0); |
| 179 | + expect(yaml.actions).to.have.length(0); |
| 180 | + expect(yaml.organizations).to.have.length(0); |
| 181 | + expect(yaml.logStreams).to.have.length(0); |
| 182 | + |
| 183 | + recordingDone(); |
| 184 | + }); |
61 | 185 | });
|
62 | 186 |
|
63 | 187 | describe('#end-to-end dump and deploy cycle', function () {
|
|
0 commit comments