Skip to content

Commit 5b93071

Browse files
More simplification
1 parent 68601ed commit 5b93071

File tree

1 file changed

+35
-70
lines changed

1 file changed

+35
-70
lines changed

__tests__/api/BundleContent/BundleMocked.test.ts

Lines changed: 35 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("MockedFilesystemTests", () => {
5858
expect(err).toBeUndefined();
5959
});
6060
it("should complain if no write permission to bundle directory", () => {
61-
// Mocks for the manifest - META-INF exists
61+
// Mocks for the manifest - META-INF doesn't exist
6262
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
6363
// Mocks for the manifest - Bundle dir writable
6464
jest.spyOn(fs, "accessSync").mockImplementationOnce(() => { throw new Error("Wibble"); });
@@ -170,8 +170,6 @@ describe("MockedFilesystemTests", () => {
170170
expect(err).toBeUndefined();
171171
});
172172
it("should detect inability to create .nodejsapp directory", () => {
173-
174-
// nodejsapps and manifest don't exist
175173
jest.spyOn(fs, "existsSync").mockImplementation((path: string) => {
176174
if (path.endsWith("nodejsapps")) {
177175
return false;
@@ -208,8 +206,6 @@ describe("MockedFilesystemTests", () => {
208206
expect(err.message).toContain("cics-deploy requires write permission to: ");
209207
});
210208
it.skip("should detect unwritable nodejsapps directory", () => {
211-
212-
// nodejsapps and manifest don't exist
213209
jest.spyOn(fs, "existsSync").mockImplementation((path: string) => {
214210
if (path.endsWith("nodejsapps")) {
215211
return false;
@@ -334,7 +330,6 @@ describe("MockedFilesystemTests", () => {
334330
});
335331
it("should complain if no overwrite permission for existing .zosattributes", () => {
336332

337-
// manifest don't exist, everying else does
338333
jest.spyOn(fs, "existsSync").mockImplementation((path: string) => {
339334
if (path.endsWith("cics.xml")) {
340335
return false;
@@ -369,16 +364,15 @@ describe("MockedFilesystemTests", () => {
369364
expect(err.message).toContain(".zosattributes already exists. Specify --overwrite to replace it.");
370365
});
371366
it("should complain if can't make a new META-INF directory", () => {
367+
jest.spyOn(fs, "accessSync").mockReturnValue(true);
368+
// manifest don't exist, everying else does
369+
jest.spyOn(fs, "existsSync").mockImplementation((path: string) => {
370+
if (path.endsWith("META-INF")) {
371+
return false;
372+
}
373+
return true;
374+
});
372375

373-
// Mocks for the manifest - META-INF exists
374-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( true ));
375-
// Mocks for the manifest - META-INF is writable
376-
jest.spyOn(fs, "accessSync").mockImplementationOnce(() => ( true ));
377-
// Mocks for the manifest - manifest exists
378-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
379-
// Mocks for the manifest - META-INF exists (on save() rather than prepareForSave())
380-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
381-
// Mocks for the manifest - META-INF creation)
382376
jest.spyOn(fs, "mkdirSync").mockImplementationOnce(() => { throw new Error("InjectedError"); });
383377

384378
let err: Error;
@@ -405,7 +399,7 @@ describe("MockedFilesystemTests", () => {
405399
return true;
406400
});
407401

408-
// Mocks for the manifest - manifest write)
402+
// Mocks for the manifest - manifest write
409403
jest.spyOn(fs, "writeFileSync").mockImplementationOnce(() => { throw new Error("InjectedError"); });
410404

411405

@@ -425,7 +419,6 @@ describe("MockedFilesystemTests", () => {
425419
});
426420
it("should complain if creating nodejsapps dir fails", () => {
427421
jest.spyOn(fs, "accessSync").mockReturnValue(true);
428-
// manifest don't exist, everying else does
429422
jest.spyOn(fs, "existsSync").mockImplementation((path: string) => {
430423
if (path.endsWith("nodejsapps")) {
431424
return false;
@@ -452,7 +445,6 @@ describe("MockedFilesystemTests", () => {
452445
});
453446
it("should complain if writing .nodejsapp file fails", () => {
454447
jest.spyOn(fs, "accessSync").mockReturnValue(true);
455-
// manifest don't exist, everying else does
456448
jest.spyOn(fs, "existsSync").mockImplementation((path: string) => {
457449
if (path.endsWith(".nodejsapp")) {
458450
return false;
@@ -479,32 +471,19 @@ describe("MockedFilesystemTests", () => {
479471
expect(err.message).toContain("InjectedError");
480472
});
481473
it("should complain if writing .profile fails", () => {
474+
jest.spyOn(fs, "accessSync").mockReturnValue(true);
475+
jest.spyOn(fs, "existsSync").mockImplementation((path: string) => {
476+
if (path.endsWith(".profile")) {
477+
return false;
478+
}
479+
return true;
480+
});
482481

483-
// Mocks for the Nodejsapp - startscript exists
484-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( true ));
485-
// Mocks for the manifest - META-INF exists
486-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( true ));
487-
// Mocks for the manifest - META-INF is writable
488-
jest.spyOn(fs, "accessSync").mockImplementationOnce(() => ( true ));
489-
// Mocks for the manifest - manifest exists
490-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
491-
// Mocks for the Nodejsapp - nodejsapp dir exists
492-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( true ));
493-
// Mocks for the Nodejsapp - nodejsapp dir writable
494-
jest.spyOn(fs, "accessSync").mockImplementationOnce(() => ( true ));
495-
// Mocks for the Nodejsapp - .nodejsapp file exists
496-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
497-
// Mocks for the Nodejsapp - .profile file exists
498-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
499-
// Mocks for the Nodejsapp - .zosattributes file exists
500-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
501-
502-
// Mocks for the nodejsapp - nodejsapps dir exists (on save() rather than prepareForSave())
503-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( true ));
504-
// Mocks for the nodejsapp - write .nodejsapp file)
505-
jest.spyOn(fs, "writeFileSync").mockImplementationOnce(() => ( true ));
506-
// Mocks for the nodejsapp - write .profile file)
507-
jest.spyOn(fs, "writeFileSync").mockImplementationOnce(() => { throw new Error("InjectedError"); });
482+
jest.spyOn(fs, "writeFileSync").mockImplementation((path: string) => {
483+
if (path.endsWith(".profile")) {
484+
throw new Error("InjectedError");
485+
}
486+
});
508487

509488
let err: Error;
510489
try {
@@ -522,34 +501,20 @@ describe("MockedFilesystemTests", () => {
522501
expect(err.message).toContain("InjectedError");
523502
});
524503
it("should complain if writing .zosattributes fails", () => {
504+
jest.spyOn(fs, "accessSync").mockReturnValue(true);
505+
jest.spyOn(fs, "existsSync").mockImplementation((path: string) => {
506+
if (path.endsWith(".zosattributes")) {
507+
return false;
508+
}
509+
return true;
510+
});
525511

526-
// Mocks for the Nodejsapp - startscript exists
527-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( true ));
528-
// Mocks for the manifest - META-INF exists
529-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( true ));
530-
// Mocks for the manifest - META-INF is writable
531-
jest.spyOn(fs, "accessSync").mockImplementationOnce(() => ( true ));
532-
// Mocks for the manifest - manifest exists
533-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
534-
// Mocks for the Nodejsapp - nodejsapp dir exists
535-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( true ));
536-
// Mocks for the Nodejsapp - nodejsapp dir writable
537-
jest.spyOn(fs, "accessSync").mockImplementationOnce(() => ( true ));
538-
// Mocks for the Nodejsapp - .nodejsapp file exists
539-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
540-
// Mocks for the Nodejsapp - .profile file exists
541-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
542-
// Mocks for the Nodejsapp - .zosattributes file exists
543-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false ));
544-
545-
// Mocks for the nodejsapp - nodejsapps dir exists (on save() rather than prepareForSave())
546-
jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( true ));
547-
// Mocks for the nodejsapp - write .nodejsapp file)
548-
jest.spyOn(fs, "writeFileSync").mockImplementationOnce(() => ( true ));
549-
// Mocks for the nodejsapp - write .profile file)
550-
jest.spyOn(fs, "writeFileSync").mockImplementationOnce(() => ( true ));
551-
// Mocks for the zosattributes - write .zosattributes file)
552-
jest.spyOn(fs, "writeFileSync").mockImplementationOnce(() => { throw new Error("InjectedError"); });
512+
// Mocks for the nodejsapp - write .zosattributes
513+
jest.spyOn(fs, "writeFileSync").mockImplementation((path: string) => {
514+
if (path.endsWith(".zosattributes")) {
515+
throw new Error("InjectedError");
516+
}
517+
});
553518

554519
let err: Error;
555520
try {

0 commit comments

Comments
 (0)