describe("Built-in instances", () => { it("should include AWS service objects", async () => { const app = jest.fn(); await laconia(app)(...handlerArgs); const lc = app.mock.calls[0][1]; expect(lc.$s3).toBeInstanceOf(AWS.S3); expect(lc.$lambda).toBeInstanceOf(AWS.Lambda); expect(lc.$ssm).toBeInstanceOf(AWS.SSM); expect(lc.$sns).toBeInstanceOf(AWS.SNS); }); });
it("should be able to process 1000 items", async () => { const oneThousand = _.range(1000); s3.getObject.mockImplementation(s3Body(oneThousand)); const reader = new S3ItemReader(new AWS.S3(), s3Params, "."); await reduceNexts(reader, 1000, undefined, (next, index) => { expect(next).toEqual({ item: index, cursor: { index: index }, finished: index === _.last(oneThousand) }); }); });
static fromRaw(event, s3 = new AWS.S3()) { const record = event.Records[0]; const { key } = record.s3.object; const { name } = record.s3.bucket; return new S3Event(name, decodeURIComponent(key.replace(/\+/g, " ")), s3); }
FileSchema.method("getInfo", function(cb){ var options = { Bucket: epa.get("s3").bucket, Key: this.name }; var s3 = new AWS.S3(); s3.headObject(options, cb); });
it("hits S3 with the configured parameters", async () => { s3.getObject.mockImplementation(s3Body(["Foo"])); const reader = new S3ItemReader(new AWS.S3(), s3Params, "."); await reader.next(); expect(s3.getObject).toHaveBeenCalledWith(s3Params, expect.any(Function)); });
const createSpier = (functionName, options) => { return new S3Spier( options.spy.bucketName, functionName, options.spy.s3 || new AWS.S3() ); }
it("throws error when path given Body is not a JSON", async () => { s3.getObject.mockImplementation( yields({ Body: { toString: () => "boom" } }) ); const reader = new S3ItemReader(new AWS.S3(), s3Params, "."); await expect(reader.next()).rejects.toThrow("not a JSON"); });
it("retrieves a directly stored array", async () => { s3.getObject.mockImplementation(s3Body(["Foo"])); const reader = new S3ItemReader(new AWS.S3(), s3Params, "."); const next = await reader.next(); expect(next).toEqual({ item: "Foo", cursor: { index: 0 }, finished: true }); });
it("retrieves array from a simple object path", async () => { s3.getObject.mockImplementation( s3Body({ list: ["Foo"] }) ); const reader = new S3ItemReader(new AWS.S3(), s3Params, "list"); const next = await reader.next(); expect(next).toHaveProperty("item", "Foo"); });
it("hits S3 with the configured parameters", async () => { s3.getObject.mockImplementation(s3Body(["Foo"])); const reader = new S3ItemReader(new AWS.S3(), s3Params, "."); await reader.next(); expect(s3.getObject).toHaveBeenCalledWith(s3Params, expect.any(Function)); });
it("retrieves next item when path given is an array of 1 item", async () => { s3.getObject.mockImplementation(s3Body(["Foo"])); const reader = new S3ItemReader(new AWS.S3(), s3Params, "."); const next = await reader.next(); expect(next).toEqual({ item: "Foo", cursor: { index: 0 }, finished: true }); });
describe("Built-in instances", () => { it("should include AWS service objects", async () => { const app = jest.fn(); await laconia(app)(...handlerArgs); const lc = app.mock.calls[0][1]; expect(lc.$s3).toBeInstanceOf(AWS.S3); expect(lc.$lambda).toBeInstanceOf(AWS.Lambda); expect(lc.$ssm).toBeInstanceOf(AWS.SSM); expect(lc.$sns).toBeInstanceOf(AWS.SNS); }); });
describe("Built-in instances", () => { it("should include AWS service objects", async () => { const app = jest.fn(); await laconia(app)(...handlerArgs); const lc = app.mock.calls[0][1]; expect(lc.$s3).toBeInstanceOf(AWS.S3); expect(lc.$lambda).toBeInstanceOf(AWS.Lambda); expect(lc.$ssm).toBeInstanceOf(AWS.SSM); expect(lc.$sns).toBeInstanceOf(AWS.SNS); }); });
static fromRaw(event, s3 = new AWS.S3()) { const record = event.Records[0]; const { key } = record.s3.object; const { name } = record.s3.bucket; return new S3Event(name, decodeURIComponent(key.replace(/\+/g, " ")), s3); }
it("retrieves next item when path given is an array of 1 item", async () => { s3.getObject.mockImplementation(s3Body(["Foo"])); const reader = new S3ItemReader(new AWS.S3(), s3Params, "."); const next = await reader.next(); expect(next).toEqual({ item: "Foo", cursor: { index: 0 }, finished: true }); });