Skip to content

Commit

Permalink
fix: change resolution of file for create:orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
mathild3r committed Feb 14, 2022
1 parent 616d43b commit 09694b4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/scripts/create-orgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export async function createOrgs(
const failedOrgs: CreateOrgData[] = [];
let orgsData: CreateOrgData[];

const orgsFilePath = path.resolve(process.cwd(), loggingPath, filePath);
const orgsFilePath = path.resolve(process.cwd(), filePath);
if (!fs.existsSync(orgsFilePath)) {
throw new Error(`File not found ${orgsFilePath}`);
}
Expand Down
38 changes: 38 additions & 0 deletions test/system/orgs:create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,44 @@ describe('`snyk-api-import help <...>`', () => {
);
}, 400000);

it('Fails to create an org as expected for non existing group ID `abc` file not in the same location as logs', (done) => {
const pathToBadJson = path.resolve(
__dirname + '/fixtures/create-orgs/fails-to-create/1-org.json',
);
const logPath = path.resolve(
__dirname + '/fixtures/create-orgs/fails-to-create-logPath/',
);

exec(
`node ${main} orgs:create --file=${pathToBadJson} --noDuplicateNames --no-includeExistingOrgsInOutput`,
{
env: {
PATH: process.env.PATH,
SNYK_TOKEN: process.env.SNYK_TOKEN_TEST,
SNYK_API: process.env.SNYK_API_TEST,
SNYK_LOG_PATH: logPath,
},
},
(err, stdout, stderr) => {
if (err) {
throw err;
}
expect(stderr).toMatch(
'All requested organizations failed to be created. Review the errors in',
);
expect(err).toBeNull();
expect(stdout).toEqual('');
const file = fs.readFileSync(
path.resolve(logPath, `abc.${FAILED_ORG_LOG_NAME}`),
'utf8',
);
expect(file).toContain('Please provide the group public id');
deleteFiles([path.resolve(logPath, `abc.${FAILED_ORG_LOG_NAME}`)]);
done();
},
);
}, 400000);

it('Fails to create orgs in --noDuplicateNames mode when org already exists ', (done) => {
const pathToBadJson = path.resolve(
__dirname +
Expand Down

0 comments on commit 09694b4

Please sign in to comment.